Routing traffic to PODS with a specific label

11/8/2019

I would like to deploy a RESTService in kubernetes behind a gateway and a service discovery. There is a moment where I will have my RestService version 1 and my RestService version 2.

Both will have the exact same URLs, but I might deploy them in pods where I label the version. When I make a call to the RESTService I would like to add something in the HTTP header indicating that I want to use my V2.

Is there any way I can route the traffic properly to the set of pods? (I'm not sure if using label is the right way). I also have to keep in mind that in the future I will have a V3 with new services and my urls will change, it cannot be something configured statically. I will also have serviceA with v1 and servicesB with v3. Both behind the same service discovery, both must be routed properly using the header parameter (or similar).

I'm not sure if Envoy is the right component for this, or is there anything else? and I'm not sure in which moment I should place this component. I'm missing something, I'm still quite confused with kubernetes. Does anybody have and example from something similar?

-- Elena
envoyproxy
kubernetes
routing

2 Answers

11/8/2019

Yes, you can have two Deployment, with different labels, e.g.

kind: Deployment
metadata:
  name: rest-service-v1
  labels:
    app: rest-service
spec:
  selector:
    matchLabels:
      app: rest-service
      version: v1
  template:
    metadata:
      labels:
        app: rest-service
        version: v1

kind: Deployment
metadata:
  name: rest-service-v3
  labels:
    app: rest-service
spec:
  selector:
    matchLabels:
      app: rest-service
      version: v3
  template:
    metadata:
      labels:
        app: rest-service
        version: v3

Then you create an Service for each:

kind: Service
metadata:
  name: rest-service-v1
spec:
  selector:
    app: rest-service
    version: v1

kind: Service
metadata:
  name: rest-service-v3
spec:
  selector:
    app: rest-service
    version: v3

and finally an Ingress object. However, the default Ingress can only route by path. You may find a 3rd party Ingress Controller that can route by Header Value

kind: Ingress
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /v1/*
        backend:
          serviceName: rest-service-v1
          servicePort: 8080
      - path: /v3/*
        backend:
          serviceName: rest-service-v3
          servicePort: 8080
-- Jonas
Source: StackOverflow

11/8/2019

Yes, a Service takes a label selector, which you can use if you set labels based on your versions. Most Ingress Controllers or other proxies than use a Service (or rather then Endpoints it manages) to pick the backend instances.

-- coderanger
Source: StackOverflow