如何使用 Envoy 将 /some-prefix 适当地路由到 gRPC 服务?
How can I use Envoy to route /some-prefix to a gRPC service appropriately?
我正在尝试设置 Envoy 以将 "/account"
路由到 gRPC 服务。如果我将路由前缀设置为 "/"
,它工作正常,但如果我引入 "/account"
,它就会中断。我试过 prefix_rewrite:"/"
但没有用。
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 3000 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/account/" }
route: {cluster: account_service, prefix_rewrite: "/" }
- match: { prefix: "/account" }
route: { cluster: account_service, prefix_rewrite: "/"}
http_filters:
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.router
clusters:
- name: account_service
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
hosts: [{ socket_address: { address: account, port_value: 3400 } }]
点击 localhost:3000/account
结果:
{
"error": "14 UNAVAILABLE: DNS resolution failed"
}
感谢您的宝贵时间。我知道它很有价值!
prefix_rewrite 将不起作用,因为它将 localhost:3000/帐户路由到 account_service:3400/。仅在您的情况下,这应该可行。这应该将 localhost:3000/account 路由到 account_service:3400/account
- match: { prefix: "/account/" }
route: {cluster: account_service}
我正在尝试设置 Envoy 以将 "/account"
路由到 gRPC 服务。如果我将路由前缀设置为 "/"
,它工作正常,但如果我引入 "/account"
,它就会中断。我试过 prefix_rewrite:"/"
但没有用。
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 3000 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/account/" }
route: {cluster: account_service, prefix_rewrite: "/" }
- match: { prefix: "/account" }
route: { cluster: account_service, prefix_rewrite: "/"}
http_filters:
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.router
clusters:
- name: account_service
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
hosts: [{ socket_address: { address: account, port_value: 3400 } }]
点击 localhost:3000/account
结果:
{
"error": "14 UNAVAILABLE: DNS resolution failed"
}
感谢您的宝贵时间。我知道它很有价值!
prefix_rewrite 将不起作用,因为它将 localhost:3000/帐户路由到 account_service:3400/。仅在您的情况下,这应该可行。这应该将 localhost:3000/account 路由到 account_service:3400/account
- match: { prefix: "/account/" }
route: {cluster: account_service}