2

I would like to route traffic to pods based on headers - with a fallback.

The desired result would be a k8s cluster where multiple versions of the same service could be deployed and routed to using header values.

svcA svcB svcC

each of these services (the main branch of git repo) would be deployed either to default namespace or labelled 'main'. any feature branch of each service can also be deployed, either into its own namespace or labelled with the branch name.

Ideally by setting a header X-svcA to a value matching a branch name, we would route any traffic to the in matching namespace or label. If there is no such name space or label, route the traffic to the default (main) pod.

if HEADERX && svcX:label 
    route->svcX:label
else
    route->svcX 

The first question - is this (or something like) even possible with istio or linkerd

Ian Wood
  • 6,515
  • 5
  • 34
  • 73

2 Answers2

1

You can do that using Istio VirtualService

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
  hosts:
  - reviews
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: reviews
        subset: v2
  - route:
    - destination:
        host: reviews
        subset: v1

Read more here.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Vasili Angapov
  • 8,061
  • 15
  • 31
  • Thanks Vasili. I think my comment is similar in my reply to Harsh Manvar. These are defined - I'm hoping for a dynamic solution so that this configuration does not need updating each time we wish to deploy a new instance of a service based on its branch. Is there anything like and IF construct in istio or linkerd? – Ian Wood May 12 '21 at 08:37
  • 1
    I hardly believe this is possible using plain Kubernetes and Istio. But I think it can be automated in CI/CD pipelines. – Vasili Angapov May 12 '21 at 10:18
0

Yes you can rout the request based on a header with Istion & Linkerd

For istio there is nice article : https://dwdraju.medium.com/simplified-header-based-routing-with-istio-for-http-grpc-traffic-ff9be55f83ca

in istio's virtual service you can update the header like :

http:
  - match:
    - headers:
        x-svc-env:
          regex: v2

For linkerd :

Kind = "service-router"
Name = "service"
Routes = [
  {
    Match {
      HTTP {
        PathPrefix = "/api/service/com.example.com.PingService"
      }
    }
    Destination {
      Service       = "pinging"
    },
  },
  {
    Match {
      HTTP {
        PathPrefix = "/api/service/com.example.com.PingService"
        Header = [
          {
            Name  = "x-version"
            Exact = "2"
          },
        ]
      }
    }
    Destination {
      Service       = "pinging"
      ServiceSubset = "v2"
    },
  }
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • As I understand it - these have to be defined. I'd really like a solution where this is dynamic - ie I don't have to go and define new destinations - rather it routes to the destination if the destination exists and if not routes to the 'main' pod? Is that possible? – Ian Wood May 12 '21 at 08:33