Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reetasingh/e2efb91bacc2dbf9625faa5607c7f348 to your computer and use it in GitHub Desktop.
Save reetasingh/e2efb91bacc2dbf9625faa5607c7f348 to your computer and use it in GitHub Desktop.
envoy - routing request to cluster based on the value of request header
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
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
http_filters:
- name: envoy.filters.http.router
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
headers:
# check the headers
- name: "x-header1"
exact_match: "abc"
- name: "x-header2"
exact_match: "pqr"
route:
# route to service_envoyproxy_io cluster
host_rewrite_literal: 127.0.0.1
cluster: service_envoyproxy_io
- match:
prefix: ""
headers:
# check the headers
- name: "x-header1"
exact_match: "xyz"
- name: "x-header2"
exact_match: "mno"
route:
# route to service_google cluster
host_rewrite_literal: 127.0.0.1
cluster: service_google
clusters:
- name: service_envoyproxy_io
connect_timeout: 30s
type: LOGICAL_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
load_assignment:
cluster_name: service_envoyproxy_io
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 5000
- name: service_google
connect_timeout: 30s
type: LOGICAL_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
load_assignment:
cluster_name: service_google
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 5003
admin:
access_log_path: /dev/null
address:
socket_address:
address: 0.0.0.0
port_value: 9901
@reetasingh
Copy link
Author

Assumes that there are 2 service running

  1. 127.0.0.1 on port 5003
  2. 127.0.0.1 on port 5000

@abrarcv170
Copy link

what if I have 100 cluster endpoints,so do I have to write 100 routing rules? is there any configuration that supports route based on the header value?eg: if the value of the target header is abc it should be forwarded to abc.svc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment