Kong系列-08-无数据库DB-less

本文介绍了Kong从1.1.0版本开始支持的无数据库模式,详细讲解了如何配置和使用这一模式。在无数据库模式下,实体通过声明式配置定义,配置文件加载到Kong后替换整个配置,并且多个Kong节点独立运行。由于缺少数据库,管理API仅支持GET方法,部分插件如acl、oauth2等不兼容,而其他如bot-detection、logging插件仍可使用。
摘要由CSDN通过智能技术生成

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
             
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值