<p>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. </p>

<p>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.</p>

<p>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).</p>

<p>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?</p>

Elena
<p>Yes, you can have <strong>two</strong> <code>Deployment</code>, with different labels, e.g.</p>

<pre><code>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
</code></pre>

<p>Then you create an <code>Service</code> for each:</p>

<pre><code>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
</code></pre>

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

<pre><code>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
</code></pre>
