istio:将istiogateway上的envoyfilter升级为新语法



我正试图将一些Lua代码仅应用于istio-ingressgateway pod。因此,基本上,我想为进入ingressgateway的每个请求运行一些Lua代码。

我已经能够使用下面显示的filters来使用旧的不推荐使用的语法。

这适用于Istio 1.4.6:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: my-filter
namespace: default
labels:
some-labels
spec:
workloadSelector:
labels:
istio: ingressgateway
authn-ns1: enabled
filters:
- filterName: envoy.lua
filterType: HTTP
listenerMatch:
listenerType: GATEWAY
listenerProtocol: HTTP
filterConfig:
inlineCode: |
function envoy_on_request(request_handle)
request_handle:logDebug("Hello World")
end

然而,我还没能用新的语法来实现这一点,我有点困惑于如何将其拼凑在一起。我试图将文档中的示例合并,https://istio.io/docs/reference/config/networking/envoy-filter/但我运气不佳。

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: my-filter
namespace: default
spec:
workloadSelector:
labels:
istio: ingress-gateway
configPatches:
- applyTo: NETWORK_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: "envoy.http_connection_manager"
patch:
operation: INSERT_BEFORE
value: # lua filter specification
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
inlineCode: |
function envoy_on_request(request_handle)
request_handle:logDebug("Hello World")
end

我还没有找到太多新语法的例子,也没有一个将过滤器应用于入口网关。我确实部署了网关,但我没有使用sidecar注入。

你知道我如何制作一个envoyfilter,以便使用新语法将Lua代码应用于每个入站请求吗?有什么好的例子可以说明如何使用新语法来做到这一点吗?如有任何建议,不胜感激。

以下是我在istio 1.5.x上尝试的内容,我使用了测试用例tests/testdata/networking/envoyfilter-without-service/configs.yaml,并将workload更改为istio: ingressgateway以匹配istio-ingressgateway。

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: test-lua
namespace: istio-system
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: HTTP_FILTER
match:
listener:
filterChain:
filter:
name: "envoy.http_connection_manager"
subFilter:
name: "envoy.router"
patch:
operation: INSERT_BEFORE
value: # lua filter specification
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
inlineCode: |
function envoy_on_request(request_handle)
request_handle:logWarn("Hello World")
end

最新更新