Open bobenut opened 1 year ago
为Ingress编排的路由,附加KongPlug,实现能够修改响应头的效果,实践KongPlug的基本附加方法。
KongPlug
按照上一篇Kong Ingress Controller实践Part1,编排路由,准备好上游服务,调通编排的API。
KongPlugin
response-transformer
echo ' apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: add-response-header config: add: headers: - "demo: injected-by-kong" plugin: response-transformer ' | sudo kubectl apply -f -
kongplugin.configuration.konghq.com/add-response-header created
sudo kubectl patch ingress demo -p '{"metadata":{"annotations":{"konghq.com/plugins":"add-response-header"}}}'
ingress.networking.k8s.io/demo patched
GET http://172.16.30.251:32736/foo/status/200 HTTP/1.1
HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 0 Connection: close Server: gunicorn/19.9.0 Date: Sun, 01 Jan 2023 16:18:51 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true demo: injected-by-kong X-Kong-Upstream-Latency: 3 X-Kong-Proxy-Latency: 1 Via: kong/3.0.1.0-enterprise-edition
Using KongPlugin resource
目标
为Ingress编排的路由,附加
KongPlug
,实现能够修改响应头的效果,实践KongPlug
的基本附加方法。准备
按照上一篇Kong Ingress Controller实践Part1,编排路由,准备好上游服务,调通编排的API。
为路由加上
KongPlugin
,修改响应头KongPlugin
,插件使用response-transformer
为响应头增加内容。KongPlugin
应用到Ingress上,应用Plugin是通过在Ingress上的注解中增加要应用的插件名称来实现。参考
Using KongPlugin resource