Envoy 流量分割

流量分割

  • HTTP router过滤器支持在一个路由中指定多个上游具有权重属性的集群,而后将流量基于权重调度至此些集群其中之一;
  • 类似流量迁移,流量分割中,分配给每个集群的权重也可以使用运行时参数进行调整;

流量分割配置格式

--
  routes
  - match: {...}
    route:
      weight_clusters: {...} 
        clusters: [] # 与当前路由关联的一个或多个集群,必选参数;
        - name: ... # 目标集群名称;也可以使用“cluster_header”字段来指定集群;二者互斥;
          weight: ... # 集群权重,取值范围为0至total_weight;
          metadata_match: {...} # 子集负载均衡器使用的端点元数据匹配条件,可选参数,仅用于上游集群中具有与此字段中设置的元数据匹配的元数端点以进行流量分配;
        total_weight: ... # 总权重值,默认为100;
        runtime_key_prefix: ... # 可选参数,用于设定键前缀,从而每个集群以“runtime_key_prefix+.+cluster[i].name”为其键名,并能够以运行时键值的方式为每个集群提供权重;其中,cluster[i].name表示列表中第i个集群名称;
      ...

流量分割配置示例

admin:
  profile_path: /tmp/envoy.prof
  access_log_path: /tmp/admin_access.log
  address:
    socket_address:
       address: 0.0.0.0
       port_value: 9901

layered_runtime:
  layers:
  - name: admin
    admin_layer: {}
       
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 80 }
    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: demoapp
              domains: ["*"]
              routes:
              routes:
              - match:
                  prefix: "/"
                route:
                  weighted_clusters:
                    clusters:
                    - name: demoappv10
                      weight: 100
                    - name: demoappv11
                      weight: 0
                    total_weight: 100
                    runtime_key_prefix: routing.traffic_split.demoapp
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
  - name: demoappv10
    connect_timeout: 0.25s
    type: STRICT_DNS
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: demoappv10
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: demoappv10
                port_value: 80

  - name: demoappv11
    connect_timeout: 0.25s
    type: STRICT_DNS
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: demoappv11
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: demoappv11
                port_value: 80

动态调整流量分发比例

# 将集群权重对调来模拟蓝绿部署,方法是在指定键(runtime_key)的值后附加以点号分隔的集群名称,并为其各自定义为相应的新权重值即可;
curl -XPOST 'http://envoy_ip:9901/runtime_modify?routing.traffic_split.demoapp.demoappv10=0&routing.traffic_split.demoapp.demoappv11=100'

# 注意:各集群的权重之和要等于total_weight的值; 

 

posted @ 2022-09-05 16:31  小吉猫  阅读(105)  评论(0编辑  收藏  举报