Kong 功能介绍

ingress绑定kong

1. 创建ingress通过注解绑定kong

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
          #konghq.com/plugins: "httpbin-auth"
  name: ingress-kong-test
  namespace: monitoring
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: grafana
            port:
              number: 3000
        path: '/'
        pathType: Prefix

2.kong控制台自动绑定svc


3.添加路由到svc



代理地址绑定CLB

1.开放白名单

需要联系腾讯云开放白名单,提供kong id以及clb id

2.clb开启后端服务功能

3.监听器绑定kong 内网代理地址

在监听器管理中绑定kong 内网代理地址

CLB的端口是80: 内网IP填 10.4.80.40 ,端口填80

CLB的端口是443: 内网IP填 10.4.80.40, 端口填443

kong基于域名限流

一、控制台配置方式

1.路由开启Tse Rate Limiting插件

2.编辑插件

  • 限流规则:指定规定时间能处理请求数
  • 根据域名限流选择:Header
  • Header选择: Host
  • 延迟时间:请求限流排队时间

点击提交则为该路由开启限流功能


二、ingress路由配置方式

配置方式通过ingress编写路由规则,将控制器指定至kong。

  1. 创建限流规则
    配置每分钟只能存在30个请求
    插件使用的是tse-rate-limiting,name是rate-limiting-header-demo
    config的字段:
  • limit_by: header,表示按照header限流。 limit_by支持: header|path|ip|service|consumer|credential。
    • 如果limit_by为header时候,config中的header_name必须填写
    • 如果limit_by为path的时候,config中的path必须填写
    • 其他情况,不需要额外填写参数
  • minute:100,表示每分钟请求上限是100
    • 限流时间窗口支持:second/minute/hour/day/year
  • default_conn_delay: 0,表示发生限流时候不等待,直接返回429状态码。如果非0,表示发生限流时候,请求延时排队时间,如果排队时间超过了,也会返回429状态码
root@management:/opt/kubernetes/KONG# cat rate-limit.yaml 
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: rate-limiting-header-demo
  namespace: test
config:
  limit_by: header
  minute: 30
  header_name: Host
  default_conn_delay: 0
plugin: tse-rate-limiting
  1. 创建ingress绑定kong 控制器
root@management:/opt/kubernetes/KONG# cat kong-test.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: kong
    konghq.com/plugins: "rate-limiting-header-demo"
  name: kong-damo
  namespace: test
spec:
  rules:
  - host: kong-test.paigod.work
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: ngx-service
            port:
              number: 80

页面查看限流功能,只具备
三、service 限流配置

  1. 创建限流规则
    插件使用的是tse-rate-limiting,配置卸载config中, name是rate-limiting-demo
    config的字段:
  • limit_by: miute,表示按照service限流
  • second:10,表示每秒请求上限是10
  • default_conn_delay: 0,表示发生限流时候不等待,直接返回429状态码
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: rate-limiting-demo
config:
  limit_by: service
  second: 10
  default_conn_delay: 0
plugin: tse-rate-limiting
2. service绑定kong 控制器

annotations中使用konghq.com/plugins引用插件,就可以绑定插件到Service上。

apiVersion: v1
kind: Service
metadata:
  annotations:
    konghq.com/plugins: "rate-limiting-demo"
  labels:
    k8s-app: nginx
    qcloud-app: nginx
  name: nginx
spec:
  ports:
  - name: 80-80-tcp
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    k8s-app: nginx
    qcloud-app: nginx
  type: ClusterIP
posted @ 2022-11-03 11:56  元气少女郭德纲!!  阅读(173)  评论(0编辑  收藏  举报