Rashmi Khandelwal
Rashmi Khandelwal

Reputation: 31

How to route on basis of Http headers in Envoy Proxy

I am sending an http request with below header.

Header = {"InstanceId" : "1"}

How to route to an cluster(endpoint) using this header value i.e. 1

What i actually want to do in envoy.yaml :

If (header. InstanceId == 1)

Route to cluster A

Else If (header. InstanceId == 2)

Route to cluster B

Can someone please help me out. Thanks in advance.

Upvotes: 3

Views: 4585

Answers (1)

norbjd
norbjd

Reputation: 11237

If you want to redirect traffic to different clusters based on the headers, you can define the following listener (the interesting part is the static_resources.listeners[0].filter_chains[0].filters[0].route_config.virtual_hosts[0].routes part, with the two matches defined) :

static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 8080
    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
          route_config:
            name: local_route
            virtual_hosts:
            - name: backend
              domains:
              - "*"
              routes:
              - match:
                  prefix: "/"
                  headers:
                    - name: "InstanceId"
                      exact_match: "1"
                route:
                  cluster: clusterA
              - match:
                  prefix: "/"
                  headers:
                    - name: "InstanceId"
                      exact_match: "2"
                route:
                  cluster: clusterB
          http_filters:
          - name: envoy.filters.http.router

Upvotes: 11

Related Questions