load-balancing - 如何在 envoy 代理中设置 Hash Key 值以实现 RING_HASH 负载平衡

标签 load-balancing envoyproxy

我正在尝试根据某些请求 header 在特使代理上设置 RING_HASH 负载平衡。来自 documentation看起来我必须在 filter_metadata

中设置哈希键
filter_metadata:
    envoy.lb:
      hash_key: "YOUR HASH KEY"

但是,我无法找出 hash_key 的可能值/表达式是什么。我尝试为哈希键配置固定值,但请求仍然不会发送到同一个上游服务器。

我的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元数据用于查找上游主机的哈希值,而不是为请求配置 key 。

还有另一个配置,hash_policy应该使用哪个。

我的最终工作特使配置如下所示。粘性 session 基于 header sticky-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
              

关于load-balancing - 如何在 envoy 代理中设置 Hash Key 值以实现 RING_HASH 负载平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69033708/

相关文章:

elasticsearch - 两台Elasticsearch服务器之间的负载平衡

docker - 如何使用 docker 暴露特使?

amazon-web-services - Istio 1.4.8 : strange 400 error when used with AWS Load balancer

reactjs - 引入ALB后,出现Mixed Content Error

azure - 我如何向 Azure 上的外部服务公开?

Kubernetes:跨两个不同命名空间的负载平衡

kubernetes - 如何增加 kubernetes 中服务可用的端口范围

amazon-web-services - 配置 Envoy 以使用 AWS ECS 和 Route53 生成的 SRV 记录

envoyproxy - 特使配置解析错误 INVALID_ARGUMENT :Unexpected token

python - 将 Envoy Dockerfile 基础镜像更新为 python 3.6+