我想在Ingress k8s对象中使用Kong的capture Group来执行uri重写。我想实现以下逻辑:https://kong_host: 30000/服务/审计/健康→(重写)https://kong_host: 30000/服务/审计/v1/健康
入口资源:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: audits
annotations:
konghq.com/plugins: audits-rewrite
spec:
rules:
- http:
paths:
- path: /service/audits/(?<path>\S+)
backend:
serviceName: audits
servicePort: 8080
KongPlugin
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: audits-rewrite
config:
replace:
uri: /service/audit/v1/$(uri_captures["path"])
plugin: request-transformer
谢谢。
正如文档中指出的那样,您不能使用v1beat1
入口API版本来捕获路径中的组。
https://docs.konghq.com/hub/kong-inc/request-transformer/示例您需要将k8s
集群升级到1.19
或更高版本才能使用此特性。
我也有类似的问题,并解决了以下配置:
入口资源:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: audits
annotations:
konghq.com/plugins: audits-rewrite
spec:
rules:
- http:
paths:
- path: /service/audits/(.*)
backend:
serviceName: audits
servicePort: 8080
KongPlugin
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: audits-rewrite
config:
replace:
uri: /service/audit/v1/$(uri_captures[1])
plugin: request-transformer