Istio destination rule subsets not working

Viewed 4655

MY istio destintion rules are not working, getting below error in kiali

enter image description here VirtualService and destination rule for echo service:

My calling echo-svc:8080 and echo-svc:8080/v1 from my another virtualservices , I'm not able to do route in specific version.

When making request from another virtualservice: echo-svc:8080/v1 or echo-svc:8080, I'm getting response from both the subsets.

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: echo-vsvc
spec:
  hosts:
  - "echo-svc.default.svc.cluster.local"
  http:
  - match:
    - uri:
        prefix: "/v1"
    route:
    - destination:
        host: echo-svc.default.svc.cluster.local
        subset: v1
  - route:
    - destination:
        host: echo-svc.default.svc.cluster.local
        subset: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: echo-destination
spec:
  host: echo-svc.default.svc.cluster.local
  subsets:
  - name: v1
    labels:
      version: v0.1
  - name: v2
    labels:
      version: v0.2

If I'm attaching my echo-service to gateway and then making service to v1 endpoint via istio-ingress, my all requests are routed to required k8s service, but if it's internal(echo service not attached to gateway) envoy is not routing the requests to required k8s service..

Update:

 $ > k get pods --show-labels
NAME                              READY   STATUS    RESTARTS   AGE     LABELS
echo-deploy-v1-bdf758994-8f54b    2/2     Running   0          2m56s   app=echo-app,pod-template-hash=bdf758994,version=v0.1
echo-deploy-v2-68bb64684d-9gg2r   2/2     Running   0          2m51s   app=echo-app,pod-template-hash=68bb64684d,version=v0.2
frontend-v2-569c89dbd8-wfnc4      2/2     Running   2          12h     app=frontend,pod-template-hash=569c89dbd8,version=v2
2 Answers

Found my mistake, for istio destination rules to work be very careful about these: https://istio.io/docs/setup/kubernetes/spec-requirements/.

My mistake was of named port for service. Updating it from "web" to "http-web" worked for me. It should be of form : <protocol>[-<suffix>]

---
apiVersion: v1
kind: Service
metadata:
  name: echo-svc
  labels:
    app: echo-app
spec:
  ports:
  - port: 80
    targetPort: 8080
    name: http-web
  selector:
    app: echo-app
---

According to the error the instances of your service are not labeled with version: v0.1 or version: v0.2 and that's why the destination rule cannot find instances for the subset.

Verify that they are labeled by executing:

kubectl get pods --show-labels

And for quick testing you can label them:

kubectl label pod [pod_name] version=v0.1
Related