gpt4 book ai didi

kubernetes - 使用Istio(1.6.0)的envoy lua过滤器添加自定义响应头

转载 作者:行者123 更新时间:2023-12-02 12:11:26 29 4
gpt4 key购买 nike

我正在运行Istio 1.6.0。
我想向来自我的服务的所有出站响应添加一些自定义 header 。所以我试图使用lua envoyfilter来实现这一目标。但是,我看不到我的代理配置正确。
我要使用的特使筛选器配置是

kind: EnvoyFilter
metadata:
name: lua-filter
namespace: istio-system
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: HTTP_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: "envoy.http_connection_manager"
subFilter:
name: "envoy.router"
patch:
operation: INSERT_BEFORE
value:
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
inlineCode: |
function envoy_on_response(response_handle)
response_handle:logInfo(" ========= XXXXX ========== ")
response_handle:headers():add("X-User-Header", "worked")
end
我的入口网关Pod确实在 istio-system命名空间中运行
❯ kgp -l istio=ingressgateway -n istio-system
NAME READY STATUS RESTARTS AGE
ingress-gateway-b4b5cffc9-wz75r 1/1 Running 0 3d12h
ingress-gateway-b4b5cffc9-znx9b 1/1 Running 0 28h
我希望在 curl 服务时会看到 X-User-Header
不幸的是,我没有看到任何自定义标题。
我尝试检查istio系统中入口网关 pods 的 proxy-configs,但根本看不到配置的 envoy.lua。我不确定是否调试正确。
 istioctl proxy-config listener ingress-gateway-b4b5cffc9-wz75r.istio-system  -n istio-system --port 443 -o json | grep "name"
"name": "0.0.0.0_443",
"name": "istio.stats",
"name": "envoy.tcp_proxy",
"name": "istio.stats",
"name": "envoy.tcp_proxy",
"name": "envoy.listener.tls_inspector",
请让我知道我缺少什么或配置错误。
关于如何进一步调试的任何建议也将非常有帮助。
非常感谢。

最佳答案

据我检查版本1.6.3和1.6.4的istio群集,您的示例工作正常。看一下我的集群中的以下代码。
我 curl 了检查

$ curl -s -I -X HEAD x.x.x.x/
HTTP/1.1 200 OK
server: istio-envoy
date: Mon, 06 Jul 2020 08:35:37 GMT
content-type: text/html
content-length: 13
last-modified: Thu, 02 Jul 2020 12:11:16 GMT
etag: "5efdcee4-d"
accept-ranges: bytes
x-envoy-upstream-service-time: 2
x-user-header: worked

我在istio ingress-gateway Pane 中使用config_dump进行了检查。
我在那里执行
kubectl exec -ti istio-ingressgateway-78db9f457d-xfhl7  -n istio-system -- /bin/bash 
config_dump的结果
curl 0:15000/config_dump | grep X-User-Header
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 128k 0 128k 0 0 9162k 0 --:--:-- --:--:-- --:--:-- 9162k
"inline_code": "function envoy_on_response(response_handle)\n response_handle:logInfo(\" ========= XXXXX ========== \")\n response_handle:headers():add(\"X-User-Header\", \"worked\")\nend\n"
因此,如您所见,它可以在请求中添加 header ,并且在istio Ingress网关中该功能处于 Activity 状态。

您能否尝试通过上述 curl 再次检查它,检查istio ingress-gateway tcp_dump并让我知道它是否对您有用?

关于kubernetes - 使用Istio(1.6.0)的envoy lua过滤器添加自定义响应头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62727066/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com