如何让 lua envoy 过滤器在 istio 集群上工作?
How to make a lua envoy filter work on the istio cluster?
我正在尝试让 lua envoy 过滤器与 istio 网关一起工作,但我添加到集群中并且它正在工作,就好像过滤器不存在一样。
我已经使用本指南在 GKE 上配置了我的 istio 集群 https://istio.io/docs/setup/kubernetes/install/kubernetes/。
有人遇到同样的问题吗?
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: edge-lua-filter
spec:
workloadLabels:
app: httpbin-gateway
filters:
- listenerMatch:
listenerType: GATEWAY
filterName: envoy.lua
filterType: HTTP
filterConfig:
inlineCode: |
-- Called on the request path.
function envoy_on_request(request_handle)
request_handle:headers():add("foo", "bar")
end
-- Called on the response path.
function envoy_on_response(response_handle)
body_size = response_handle:body():length()
response_handle:headers():add("response-body-size", tostring(body_size))
end
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: httpbin-gateway
namespace: foo
spec:
selector:
istio: ingressgateway # use Istio default gateway implementation
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin
namespace: foo
spec:
hosts:
- "*"
gateways:
- httpbin-gateway
http:
- route:
- destination:
port:
number: 8000
host: httpbin.foo.svc.cluster.local
您正在将过滤器应用于 GATEWAY。入口网关的 "app" 名称是 "istio-ingressgateway",而不是 "httpbin-gateway"
您有 2 个选择:
- 更改工作负载标签
workloadLabels:
app: istio-ingressgateway
或
- 删除工作负载标签。 Istio 将自动将更改应用到 GATEWAY pod
我同意 larsitto,您可能对 workloadLabels 有问题 - 尝试将其留空或指定您在您的部署>规范>模板>标签[]
此代码适用于我,例如:
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: hello_world
spec:
workloadLabels:
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
listenerProtocol: HTTP
filterName: envoy.lua
filterType: HTTP
filterConfig:
inlineCode: |
...
如果使用 filterType HTTP,还需要定义值为 HTTP 的 listenerProtocol 属性。
另见:
https://istio.io/docs/reference/config/networking/v1alpha3/envoy-filter/ :
注意 3:对于 filterType: HTTP 的过滤器,您必须包含一个带有 listenerProtocol: HTTP 的 listenerMatch 部分,否则过滤器无效。
我正在尝试让 lua envoy 过滤器与 istio 网关一起工作,但我添加到集群中并且它正在工作,就好像过滤器不存在一样。
我已经使用本指南在 GKE 上配置了我的 istio 集群 https://istio.io/docs/setup/kubernetes/install/kubernetes/。
有人遇到同样的问题吗?
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: edge-lua-filter
spec:
workloadLabels:
app: httpbin-gateway
filters:
- listenerMatch:
listenerType: GATEWAY
filterName: envoy.lua
filterType: HTTP
filterConfig:
inlineCode: |
-- Called on the request path.
function envoy_on_request(request_handle)
request_handle:headers():add("foo", "bar")
end
-- Called on the response path.
function envoy_on_response(response_handle)
body_size = response_handle:body():length()
response_handle:headers():add("response-body-size", tostring(body_size))
end
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: httpbin-gateway
namespace: foo
spec:
selector:
istio: ingressgateway # use Istio default gateway implementation
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin
namespace: foo
spec:
hosts:
- "*"
gateways:
- httpbin-gateway
http:
- route:
- destination:
port:
number: 8000
host: httpbin.foo.svc.cluster.local
您正在将过滤器应用于 GATEWAY。入口网关的 "app" 名称是 "istio-ingressgateway",而不是 "httpbin-gateway"
您有 2 个选择:
- 更改工作负载标签
workloadLabels:
app: istio-ingressgateway
或
- 删除工作负载标签。 Istio 将自动将更改应用到 GATEWAY pod
我同意 larsitto,您可能对 workloadLabels 有问题 - 尝试将其留空或指定您在您的部署>规范>模板>标签[]
此代码适用于我,例如:
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: hello_world
spec:
workloadLabels:
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
listenerProtocol: HTTP
filterName: envoy.lua
filterType: HTTP
filterConfig:
inlineCode: |
...
如果使用 filterType HTTP,还需要定义值为 HTTP 的 listenerProtocol 属性。
另见:
https://istio.io/docs/reference/config/networking/v1alpha3/envoy-filter/ :
注意 3:对于 filterType: HTTP 的过滤器,您必须包含一个带有 listenerProtocol: HTTP 的 listenerMatch 部分,否则过滤器无效。