In ISTIO VirtualService and DestinationRule Not behaving properly, find the manifest below,
when trying to curl my service its distributing traffic to both v1 and v2 pod even after mentioning v1 only in virtual service
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-v1
namespace: istio
labels:
app: nginx
version: v1
spec:
selector:
matchLabels:
app: nginx
version: v1
template:
metadata:
labels:
app: nginx
version: v1
spec:
containers:
- name: nginx
image: chaitanya305/good-morning
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-v2
namespace: istio
labels:
app: nginx
version: v2
spec:
selector:
matchLabels:
app: nginx
version: v2
template:
metadata:
labels:
app: nginx
version: v2
spec:
containers:
- name: nginx
image: chaitanya305/good-night
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
namespace: istio
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30080
type: NodePort
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-virtualservice
namespace: istio
spec:
hosts:
- nginx-svc.istio.svc.cluster.local
http:
- route:
- destination:
host: nginx-svc.istio.svc.cluster.local
subset: v1
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: my-destinationrule
namespace: istio
spec:
host: nginx-svc.istio.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
When i try to acces below url
curl nginx-svc.istio.cluster.local
traffic goes to both v1 and v2 pod, as per virtual service rule it suppose to go to v1 only. which is suppose to provide output as Hi good morning only.
root@jenkins-deployment-f4d955ff4-kpxgj:/tmp# cat bash2.sh
while true
do
curl nginx-svc.istio.svc.cluster.local
sleep 2
done
root@jenkins-deployment-f4d955ff4-kpxgj:/tmp# ./bash2.sh
Hi good morning
good Night sweet dreams
Hi good morning
Hi good morning
Hi good morning
good Night sweet dreams
good Night sweet dreams
Hi good morning
^Croot@jenkins-deployment-f4d955ff4-kpxgj:/tmp#
Chaitanya Golhar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
The pod you are running the curl command should have istio-proxy sidecar. The rules are considered only in the source pod. So the source pod needs the proxy sidecar. This will also work if you don’t have proxies for the nginx-v1 and nginx-v2 deployments. Although the requests will be plaintext.
zpyder k is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.