Last active
March 10, 2023 15:23
-
-
Save reetasingh/e2efb91bacc2dbf9625faa5607c7f348 to your computer and use it in GitHub Desktop.
envoy - routing request to cluster based on the value of request header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Assumes that there are 2 service running
- 127.0.0.1 on port 5003
- 127.0.0.1 on port 5000
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
run this
envoy -c envoy_config_for_routing_using_request_header.yaml