Skip to content

Instantly share code, notes, and snippets.

@hermanbanken
Last active August 26, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanbanken/f756aae18299f8674a7f498f8dfcef5f to your computer and use it in GitHub Desktop.
Save hermanbanken/f756aae18299f8674a7f498f8dfcef5f to your computer and use it in GitHub Desktop.
Envoy Cluster SubSet Load Balancing
# Requires Envoy >= 1.14.
# Validate:
# $ docker run -v $PWD:/data envoyproxy/envoy /usr/local/bin/envoy -c /data/config-equivalent.yaml
#
# Docs: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/subsets
# Other examples: https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/examples
static_resources:
listeners:
- name: listener0
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
codec_type: AUTO
stat_prefix: ingress_http
http_filters:
- name: envoy.filters.http.header_to_metadata
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.header_to_metadata.v3.Config
request_rules:
- header: x-slice
on_header_present:
metadata_namespace: envoy.lb
key: slice
- name: envoy.filters.http.router
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: target, host_rewrite_literal: target }
clusters:
- connect_timeout: 1s
name: target
type: strict_dns
http2_protocol_options: {}
lb_subset_config:
fallback_policy: ANY_ENDPOINT
default_subset: { "slice": "default" }
subset_selectors:
- keys: ["slice"]
fallback_policy: NO_FALLBACK
load_assignment:
cluster_name: target
endpoints:
- lb_endpoints:
- metadata:
filter_metadata: { "envoy.lb": { "slice": "target-1" } }
endpoint:
address:
socket_address:
address: target-1
port_value: 80
- metadata:
filter_metadata: { "envoy.lb": { "slice": "target-1" } }
endpoint:
address:
socket_address:
address: target-2
port_value: 80
- metadata:
filter_metadata: { "envoy.lb": { "slice": "target-1" } }
endpoint:
address:
socket_address:
address: target-3
port_value: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment