加权轮询:ROUND_ROBIN,权重都为1时为轮询,按照权重虚拟出多个端点进行轮询调度。适合短连接。
加权最少请求:LEAST_REQUEST,按照实际负载情况和权重来进行调度,适合长连接的情况,检查后端主机状态也要消耗时间。
环哈希:RING_HASH,根据请求的特点将请求固定到某个端点,计算cookie、header头或ip等属性将请求分配到哈希环某个区间中对应的节点。在哈希环中虚拟出很多节点,权重高的节点对应着更多的虚拟节点。环的个数在envoy中可以定义。
磁悬浮:MAGLEV 同环哈希,但是大小固定为65537,且需要主机映射的节点填满整个环。
随机:RANDOM 随机调度
原始目标集群负载均衡:ORIGINAL_DST_LB
负载均衡相关配置:
clusters:
- name: ...
...
load_assignment: {...}
cluster_name: ...
endpoints: [] # LocalityLbEndpoints列表, 每个列表项主要由位置、 端点列表、 权重和优先级四项组成;
- locality: {...} # 位置定义
region: ...
zone: ...
sub_zone: ...
lb_endpoints: [] # 端点列表
- endpoint: {...} # 端点定义
address: {...} # 端点地址
health_check_config: {...} # 当前端点与健康状态检查相关的配置;
load_balancing_weight: ... # 当前端点的负载均衡权重, 可选;
metadata: {...} # 基于匹配的侦听器、 过滤器链、 路由和端点等为过滤器提供额外信息的元数据, 常用用于提供服务配置或辅助负载均衡;
health_status: ... # 端点是经EDS发现时, 此配置项用于管理式设定端点的健康状态, 可用值有UNKOWN、 HEALTHY、 UNHEALTHY、DRAINING、 TIMEOUT和DEGRADED;
load_balancing_weight: {...} # 权重
priority: ... # 优先级
policy: {...} # 负载均衡策略设定
drop_overloads: [] # 过载保护机制, 丢弃过载流量的机制;
overprovisioning_factor: ... # 整数值, 定义超配因子( 百分比) , 默认值为140, 即1.4;
endpoint_stale_after: ... # 过期时长, 过期之前未收到任何新流量分配的端点将被视为过时, 并标记为不健康; 默认值0表示永不过时;
lb_subset_config: {...}
ring_hash_lb_config: {...}
original_dst_lb_config: {...}
least_request_lb_config: {...}
common_lb_config: {...}
health_panic_threshold: ... # Panic阈值, 默认为50%;
zone_aware_lb_config: {...} # 区域感知路由的相关配置;
locality_weighted_lb_config: {...} # 局部权重负载均衡相关的配置;
ignore_new_hosts_until_first_hc: ... # 是否在新加入的主机经历第一次健康状态检查之前不予考虑进负载均衡;轮询ROUND_ROBIN:
clusters:
- name: webcluster1
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
load_assignment:
cluster_name: webcluster1
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: service_red
port_value: 80
load_balancing_weight: 1
- endpoint:
address:
socket_address:
address: service_blue
port_value: 80
load_balancing_weight: 3
- endpoint:
address:
socket_address:
address: service_green
port_value: 80
load_balancing_weight: 5加权最少请求LEST_REQUEST:
clusters:
- name: webcluster1
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: LEAST_REQUEST
least_request_lb_config:
choice_count: 2 # 从中选两个点并选择连接数少的那个
http2_protocol_options: {}
load_assignment:
cluster_name: webcluster1
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: service_red
port_value: 80
load_balancing_weight: 1
- endpoint:
address:
socket_address:
address: service_blue
port_value: 80
load_balancing_weight: 3
- endpoint:
address:
socket_address:
address: service_green
port_value: 80
load_balancing_weight: 5环哈希ring-hash:
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
name: listener_http
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: backend
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: webcluster1
hash_policy:
- header:
header_name: User-Agent
http_filters:
- name: envoy.router
clusters:
- name: webcluster1
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: RING_HASH
ring_hash_lb_config:
maximum_ring_size: 1048576
minimum_ring_size: 1024
http2_protocol_options: {}
load_assignment:
cluster_name: webcluster1
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: myservice
port_value: 80