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?
There were some indentation issues. I resolved it referring the following links
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.
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.