How to resolve Istio traffic routing bug?

11/19/2018

For the below files , ISTIO is showing output in the first v1 app only. If I change the version of the v1 the output changes. So the traffic is not moving to the other version at all.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: sampleweb
  namespace: default
spec:
  hosts:
  - "web.xyz.com"
  gateways:
  - http-gateway
  http:
  - route:
    - destination:
        port:
          number: 8080
        host: web
        subset: v1
      weight: 30
  - route:
    - destination:
        port:
          number: 8080
        host: web
        subset: v2
      weight: 30
  - route:
    - destination:
        port:
          number: 8080
        host: web
        subset: v3
      weight: 40

---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: samplewebdr
  namespace: default
spec:
  host: web
  subsets:
  - name: v1
    labels:
      app: web
      version: prod
  - name: v2
    labels:
      app: web
      version: baseline
  - name: v3
    labels:
      app: web
      version: canary
  trafficPolicy:
    tls:
      mode: ISTIO_MUTUAL

Can anyone please help on this?

-- Subit Das
istio
kubernetes
spinnaker

3 Answers

11/20/2018

There were some indentation issues. I resolved it referring the following links

https://raw.githubusercontent.com/istio/istio/release-1.0/samples/bookinfo/networking/destination-rule-all-mtls.yaml

-- Subit Das
Source: StackOverflow

11/20/2018

Your problem is that you have created a VirtualService with 3 rules in it. The first rule, which has no specific match criteria, is therefore always the one that gets invoked. When you have multiple rules in a VirtualService, you need to be careful to order them properly, as described here.

That said, in your case, you really don't want multiple rules, but rather a single rule with multiple weighted destinations like this:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: sampleweb
  namespace: default
spec:
  hosts:
  - "web.xyz.com"
  gateways:
  - http-gateway
  http:
  - route:
    - destination:
        port:
          number: 8080
        host: web
        subset: v1
      weight: 30
    - destination:
        port:
         number: 8080
        host: web
        subset: v2
      weight: 30
    - destination:
        port:
          number: 8080
        host: web
        subset: v3
      weight: 40

Btw, although harmless, you don't need to include the app: web label in you DestinationRule subsets. You only need the labels that uniquely identify the difference between the subsets of the web service.

-- Frank B
Source: StackOverflow

11/19/2018

I think the problem is that for all versions you've got the same label app: web so istio directs traffic to pods with these labels they're just happened to be the same pod. You need to specify different labels for different versions like vor v2 the label is version: v1, for v2 - version: v2 and you also need to create pods with these labels.

-- Anna Slastnikova
Source: StackOverflow