如何在 envoy 代理中为 RING_HASH 负载平衡设置哈希键值
How to set Hash Key value in envoy proxy for RING_HASH load balancing
我正在尝试根据某些请求 header 在 envoy 代理上设置 RING_HASH 负载平衡。从 documentation 看来我必须在 filter_metadata
中设置散列键
filter_metadata:
envoy.lb:
hash_key: "YOUR HASH KEY"
但是,我无法找出 hash_key 的可能 values/expressions 是什么。我尝试为哈希键配置一个固定值,但仍然请求不会转到同一个上游服务器。
我的envoy.yaml
admin:
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: 10000 }
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
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: some_service }
http_filters:
- name: envoy.filters.http.router
clusters:
- name: some_service
connect_timeout: 0.25s
type: STATIC
lb_policy: RING_HASH
metadata:
filter_metadata:
envoy.lb:
hash_key: "fixed_value"
load_assignment:
cluster_name: some_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 172.19.0.2
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.3
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.4
port_value: 8080
我想,envoy.lb
元数据用于查找上游主机的哈希值而不是为请求配置密钥。
还有一个配置,hash_policy应该使用。
我的最终工作 envoy 配置如下所示。粘性session基于headersticky-key
admin:
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: 10000 }
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
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: some_service
hash_policy:
- header:
header_name: sticky-key
http_filters:
- name: envoy.filters.http.router
clusters:
- name: some_service
connect_timeout: 0.25s
type: STATIC
lb_policy: RING_HASH
load_assignment:
cluster_name: some_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 172.19.0.2
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.3
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.4
port_value: 8080
我正在尝试根据某些请求 header 在 envoy 代理上设置 RING_HASH 负载平衡。从 documentation 看来我必须在 filter_metadata
filter_metadata:
envoy.lb:
hash_key: "YOUR HASH KEY"
但是,我无法找出 hash_key 的可能 values/expressions 是什么。我尝试为哈希键配置一个固定值,但仍然请求不会转到同一个上游服务器。
我的envoy.yaml
admin:
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: 10000 }
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
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: some_service }
http_filters:
- name: envoy.filters.http.router
clusters:
- name: some_service
connect_timeout: 0.25s
type: STATIC
lb_policy: RING_HASH
metadata:
filter_metadata:
envoy.lb:
hash_key: "fixed_value"
load_assignment:
cluster_name: some_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 172.19.0.2
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.3
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.4
port_value: 8080
我想,envoy.lb
元数据用于查找上游主机的哈希值而不是为请求配置密钥。
还有一个配置,hash_policy应该使用。
我的最终工作 envoy 配置如下所示。粘性session基于headersticky-key
admin:
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: 10000 }
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
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: some_service
hash_policy:
- header:
header_name: sticky-key
http_filters:
- name: envoy.filters.http.router
clusters:
- name: some_service
connect_timeout: 0.25s
type: STATIC
lb_policy: RING_HASH
load_assignment:
cluster_name: some_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 172.19.0.2
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.3
port_value: 8080
- endpoint:
address:
socket_address:
address: 172.19.0.4
port_value: 8080