Route weighted traffic internally with Istio across K8s cluster

12/9/2019

I have 2 applications (Web and Api) and there is 2 services and 2 Istio virtualServices respectively. Also there is 2 versions(v1 and v2) of each services.

I wish to do 3 things-

  1. For Web, all traffic except test-user will route 100% to version v1 only.

  2. For Web, for test-user traffic will route 100% to version v2 only (This is vice-versa of 1st point.). Before going to live, QA team will perform testing on version v2, once verified by QA team, will move traffic to 100% to v2 for every user and delete the version v1.

  3. For Api, traffic will distribute 95% for version v1(stable) and 5% for version v2(release).

Web Manifest file:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: web-vs
spec:
  hosts:
  - web.example.com
  http:
  - match:
    - headers:
        end-user:
          exact: test-user
    route:
    - destination:
        host: web-svc
        subset: v2
  - route:
    - destination:
        host: web-svc
        subset: v1
---
apiVersion: v1
kind: Service
metadata:
  name: web-svc
  labels:
    app: web
spec:
  ports:
  - name: http
    port: 3000
    targetPort: 3000
  selector:
    app: web

API manifest file:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api-vs    -------------> #1
spec:
  hosts:
  - api-svc
  http:
  - route:
    - destination:
        host: api-svc
        subset: v1
        weight: 95
    - destination:
        host: api-svc
        subset: v2
        weight: 5
---
apiVersion: v1
kind: Service
metadata:
  name: api-svc    -------------> #2
  labels:
    app: api
spec:
  ports:
  - name: http
    port: 8000
    targetPort: 8000
  selector:
    app: api

Traffic routing policy-

  1. When we will hit the url web.example.com and it will serve the traffic from service web-svc. (This has been setup)

  2. In the backend, service web-svc will call service api-svc internally and service api-svc will distribute the traffic 95% to v1 and 5% to v2 respectivley. (This is what I am struggling to do with wieghted routing.)

-- Ashish Kumar
eks
google-kubernetes-engine
istio
kubernetes

1 Answer

12/9/2019

I think the issue is with indentations and hosts. From Istio docs, try like this:

hosts:
- api-svc
http:
- route:
  - destination:
      host: api-svc
      subset: v1
    weight: 95
  - destination:
      host: api-svc
      subset: v2
    weight: 5

Edited: destination hosts.

-- Emil Gi
Source: StackOverflow