Kubernetes的Ingress资源基于HTTP报文头和路径定义路由策略。在大多数情况下这已足够,但有时希望在Ingress级别对路由进行更多控制,通用的Ingress资源无法满足需求,所以Kong提供KongIngress CRD对Ingress资源进行了扩展,以提供对代理行为更细粒度控制,KongIngress与Ingress资源协同工作并对其进行扩展。它并不是在Kubernetes中替代Ingress资源。使用KongIngress可以修改Kong中与Ingress资源相关的Upstream,Service和Route实体的所有属性。
KongIngress资源的定义:
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
创建KongIngress资源后,可以使用configuration.konghq.com声明将KongIngress资源与Ingress或Service资源关联:
- 将声明添加到Ingress资源后,路由配置将更新,这意味着与带声明的Ingress关联的所有路由都将更新为使用KongIngress的route部分中定义的值。
- 将声明添加到Kubernetes中的Service资源时,Kong中的相应Service和Upstream将更新为使用关联的KongIngress资源中定义的proxy和upstream部分中定义的值。
下面介绍一下如何使用KongPlugin资源,先将Kong初始化为空配置。
curl -i http://192.168.1.55:32080
HTTP/1.1 404 Not Found
Date: Tue, 24 Dec 2019 14:03:40 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 48
Server: kong/1