Is it possible to apply virtualService and Destination to the specified version of the POD

Viewed 72

I have two http services A and B, and each service has two versions v1 and v2.

If A(v1) calls B, eg. use http://b:8080, both B(v1) and B(v2) can answer the call.

When A (v2) calls B, only B (v2) gets the call.

How should I define virtualService and Destination rules in this scenario?

1 Answers

You would need to match the pod from where the traffic is coming from with sourceLabels and the route it to the specific subsets. Here's an example of how that might look like:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: route-av1-bv1-2
spec:
  hosts:
  - service-b
  http:
#Match the traffic from App-A-version-1 towards App-B versions 1 & 2
  - match:
    - sourceLabels:
        app: av1
    - route:
      - destination:
          host: service-b
          subset: v1
    - route:
      - destination:
          host: service-b
          subset: v2  
#Match the traffic from App-A-version-2 towards only App-B-version-2
  - match:
    - sourceLabels:
        app: av2
    - route:
      - destination:
          host: service-b
          subset: v2

And the DestinationRule:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: route-av1-bv1-2
spec:
  host: service-b
  subsets:
  - name: v1
    labels:
      app: bv1
  - name: v2
    labels:
      app: bv2

Istio traffic management sections describes the VirtualService and DestinationRule very well along with some good examples.

Related