Kong无数据库介绍
Kong在1.1.0版本(2019-03-27)开始支持无数据库模式,只需要将kong.conf中的配置项database = off即可启用无数据库方式。
- 无数据库采用声明方式定义实体,所有的实体都配置在其中。一旦该文件加载到Kong中,它将替换整个配置。当需要增量更改时,将对声明性配置文件进行更改,然后将其全部重新加载。
- 由于没有中心数据库进行协调,多个Kong节点是完全彼此独立。
- 由于配置实体的唯一方式是通过声明性配置,管理API的CRUD操作只支持只读方法,即GET方法,不支持POST、DELETE等方法。
无数据库加载实体声明的方式:
- 在kong.conf配置文件中配置declarative_config = /etc/kong/kong.yaml
- 调用管理API,一次性加载声明配置。
由于没有数据库,有些Kong的插件将不再能够使用,有些插件能够部分使用。
-
兼容的插件
bot-detection
correlation-id
cors
datadog
file-log
http-log
tcp-log
udp-log
syslog
ip-restriction
prometheus
zipkin
request-transformer
response-transformer
request-termination -
部分兼容的插件
acl
basic-auth
hmac-auth
jwt
key-auth
rate-limiting
response-ratelimiting
key-auth -
不兼容的插件
oauth2
Kong无数据库配置
将Kong改为无数据库模式。
vi /etc/kong//kong.conf
database = off # Determines which of PostgreSQL or Cassandra
# this node will use as its datastore.
# Accepted values are `postgres`,
# `cassandra`, and `off`.
- 声明配置文件方式
前面说过,可以在声明性配置文件中定义配置数据,Kong会一次性加载到内存。我们先需要一个kong.yml文件,可以通过一个初始化命令生成。
mkdir kong
cd kong
pwd
/root/kong
kong config -c kong.conf init
ls
kong.yml
kong.yml是一个模板文件。在其中定义一个service和route。
vi kong.yml
......
_format_version: "1.1"
# Each Kong entity (core entity or custom entity introduced by a plugin)
# can be listed in the top-level as an array of objects:
services:
- name: example-service
url: http://www.baidu.com
# Entities can store tags as metadata
tags:
- example
# Entities that have a foreign-key relationship can be nested:
routes:
- name: example-route
paths:
- /foo
......
将声明配置文件加载到Kong。
vi /etc/kong//kong.conf
declarative_config = /root/kong/kong.yml # The path to the declarative configuration
# file which holds the specification of all
# entities (Routes, Services, Consumers, etc.)
# to be used when the `database` is set to