Kong Ingress Controller的CRD详细说明

说明

这是API网关Kong的学习笔记中的一篇,使用过程中遇到的问题和解决方法记录在API网关Kong的使用过程中遇到的问题以及解决方法

API网关Kong学习笔记(二):Kong与Kubernetes集成的方法中介绍过Kong Ingress Controller定义的CustomResourceDefinitions,那时候了解不多,没详细记录用法。把Kong Ingress Controller的代码读了以后,基本上摸清了它的工作过程,这里详细记录一下KongPluginKongConsumerKongIngressKongCredential的用法。

KongPlugin的用法

KongPlugin的格式如下:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: <object name>
  namespace: <object namespace>
  labels: global: "true" # optional, please note the quotes around true
consumerRef: <optional, name of an existing consumer> # optional
disabled: <boolean>  # optional
config:
    key: value
plugin: <name-of-plugin>

Kong实现了很多插件,每个插件的配置都不相同,这些不同的配置都体现在config中。

rate-limiting插件的一个实例可能是这个样子的:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: http-svc-consumer-ratelimiting
consumerRef: consumer-team-x
config:
  hour: 1000
  limit_by: ip
  second: 100
plugin: rate-limiting

ip-restriction插件的一个实例可能是下面这个样子:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: echo-ip-restriction
  namespace: demo-echo
disabled: false  # optional
plugin: ip-restriction
config:
#  whitelist:     #用“,”间隔的一组IP或者CIDR,要么白名单、要么黑名单
  blacklist: 192.168.33.12,172.16.129.1

它们的config字段的结构是不同的,每个插件的config字段中可以有哪些配置,在每个插件插件的文档中可以找到:rate-limitingip-restriction

KongIngress的用法

KongIngress中是一些增强配置的,这一点要特别注意。kong ingress controller会将kubernetes中原生定义的ingress转换成kong中的配置,但是kong的配置是要多于标准ingress中的内容的,多出的这些配置在KongIngress中设置。

KongIngress的结构如下,由upstreamproxyroute三部分组成:

apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: configuration-demo
upstream:
  hash_on: none
  hash_fallback: none
  healthchecks:
    active:
      concurrency: 10
      healthy:
        http_statuses:
        - 200
        - 302
        interval: 0
        successes: 0
      http_path: "/"
      timeout: 1
      unhealthy:
        http_failures: 0
        http_statuses:
        - 429
        interval: 0
        tcp_failures: 0
        timeouts: 0
    passive:
      healthy:
        http_statuses:
        - 200
        successes: 0
      unhealthy:
        http_failures: 0
        http_statuses:
        - 429
        - 503
        tcp_failures: 0
        timeouts: 0
    slots: 10
proxy:
  protocol: http
  path: /
  connect_timeout: 10000
  retries: 10
  read_timeout: 10000
  write_timeout: 10000
route:
  methods:
  - POST
  - GET
  regex_priority: 0
  strip_path: false
  preserve_host: true
  protocols:
  - http
  - https

upstream中配置的负载均衡算法、健康检查方法等,proxy中设置的kong与backend server通信的时超时时间、重试次数等,route中设置的是路由匹配的协议、方法以及路由的优先级。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值