可以在 Istio 中使用 Envoy Filter 实现 Nginx 入口注解等效项。
更具体地说,使用HTTP Lua filter。
具有 HTTP Lua 过滤器的特使过滤器示例:
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: reviews-lua
namespace: bookinfo
spec:
workloadSelector:
labels:
app: reviews
configPatches:
# The first patch adds the lua filter to the listener/http connection manager
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
portNumber: 8080
filterChain:
filter:
name: "envoy.http_connection_manager"
subFilter:
name: "envoy.router"
patch:
operation: INSERT_BEFORE
value: # lua filter specification
name: envoy.lua
config:
inlineCode: |
function envoy_on_request(request_handle)
-- Make an HTTP call to an upstream host with the following headers, body, and timeout.
local headers, body = request_handle:httpCall(
"lua_cluster",
{
[":method"] = "POST",
[":path"] = "/acl",
[":authority"] = "internal.org.net"
},
"authorize call",
5000)
end
# The second patch adds the cluster that is referenced by the lua code
# cds match is omitted as a new cluster is being added
- applyTo: CLUSTER
match:
context: SIDECAR_OUTBOUND
patch:
operation: ADD
value: # cluster specification
name: "lua_cluster"
type: STRICT_DNS
connect_timeout: 0.5s
lb_policy: ROUND_ROBIN
hosts:
- socket_address:
protocol: TCP
address: "internal.org.net"
port_value: 8888
例如:
nginx.ingress.kubernetes.io/proxy-body-size 可以通过size = buffer:length() 实现。
nginx.ingress.kubernetes.io/proxy-read-timeout 或
nginx.ingress.kubernetes.io/proxy-send-timeout 是自定义超时,可以通过 httpCall(5000) 实现。
方法的完整列表可以在here找到。
希望这会有所帮助。
更新:
重读 nginx 注释后,getBytes() 看起来更适合nginx.ingress.kubernetes.io/proxy-buffer-size 而不是buffer:lenght()。
getBytes()
缓冲区:getBytes(索引,长度)
从缓冲区中获取字节。默认情况下,Envoy 不会复制所有缓冲区
字节到 Lua。这将导致复制缓冲区段。 索引
是一个整数并提供要复制的缓冲区起始索引。 长度
是一个整数并提供要复制的缓冲区长度。 索引 +
长度必须小于缓冲区长度。
所以buffer:getBytes(0, 8000) 应该从类似于nginx.ingress.kubernetes.io/proxy-buffer-size: "8k" 的缓冲区加载8k 字节。