Istio Request Routing for user-facing service doesn't work with ingress-gateway

3/9/2019

I have a problem with Istio Request Routing directly behind the Istio Ingress Gateway:

request routing

I have simple node.js app (web-api) in 2 versions (v1, v2) with an Istio Ingress Gateway directly in frontand an Istio VirtualService that is supposed to do a 80/20 distribution between version 1 and 2 but it doesn't. Kiali shows a 50/50 distribution.

When I add a simple frontend service that just passes the request through, everything works as expected. frontend added According to the Istio documentation using an Istio ingress allows for request routing rules in user-facing services. But for me it doesn't and I don't understand why?

deployment.yaml:

apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: web-api-v1
spec:
  selector:
    matchLabels:
      app: web-api
      project: istio-test
      version: v1
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: web-api
        project: istio-test
        version: v1
    spec:
      containers:
      - image: web-api:1
        name: web-api-v1
        env:
        - name: VERS
          value: "=> Version 1"
        ports:
        - containerPort: 3000
          name: http
      restartPolicy: Always    
---
apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: web-api-v2
spec:
  selector:
    matchLabels:
      app: web-api
      project: istio-test
      version: v2
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: web-api
        project: istio-test
        version: v2
    spec:
      containers:
      - image: web-api:1
        name: web-api-v1
        env:
        - name: VERS
          value: "=> Version 2"
        ports:
        - containerPort: 3000
          name: http
      restartPolicy: Always    
---

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: web-api
  labels:
    app: web-api
    project: istio-test
spec:
  type: NodePort
  ports:
    - port: 3000  
      name: http
      protocol: TCP
  selector:
    app: web-api
---

istio-ingress.yaml:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: default-gateway-ingress
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
--- 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtualservice-ingress
spec:
  hosts:
  - "*"
  gateways:
  - default-gateway-ingress
  http:
  - match:
    - uri:
        exact: /test
    route:
    - destination:
        host: web-api
        port:
          number: 3000
--- 

istio-virtualservice.yaml:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: web-api
spec:
  hosts:
  - web-api
  http:
  - route:
    - destination:
        host: web-api
        subset: v1
      weight: 80  
    - destination:
        host: web-api
        subset: v2 
      weight: 20   
---

I have put this example on https://github.com/Harald-U/istio-test

-- Harald Uebele
istio
kubernetes

2 Answers

3/11/2019

With Stefans help I was able to fix it this way:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtualservice-ingress
spec:
  hosts:
  - "*"
  gateways:
  - default-gateway-ingress
  http:
  - match:
    - uri:
        exact: /test
    route:
      - destination:
          host: web-api
          subset: v1
        weight: 80  
      - destination:
          host: web-api
          subset: v2 
        weight: 20       
---

Now I have the ingress rule (match /test) and request routing is working correctly, too.

-- Harald Uebele
Source: StackOverflow

3/10/2019

You have to attach the web-api virtual service to the gateway and delete the virtualservice-ingress object.

Here is how the web-api virtual service should look like:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: web-api
spec:
  hosts:
  - "*"
  gateways:
  - default-gateway-ingress
  http:
  - route:
    - destination:
        host: web-api
        subset: v1
      weight: 80  
    - destination:
        host: web-api
        subset: v2 
      weight: 20   
-- Stefan P.
Source: StackOverflow