Openshift - VirtualService not applying traffic weight

#1

I’m trying to better understand how the DestinationRule and VirtualService components work to implement an automated canary deployment demo, but for some reason I’m hitting a wall.

When I spin up the bookinfo VirtualService demo, things work exactly as I would expect: when I route 100% of the traffic to v1, no review stars show up in the UI. When I route 50% to v1 and 50% to v2, I get either no stars or black stars half the time. Etc.

However, when trying to create my own virtual service with the exact same set-up, traffic being “round robined” to ALL 3 versions and disregarding the weights I have in my VirtualService. I thought it was a misconfiguration, so I wrote a super-simple Flask proxy to hit the functioning ‘reviews’ service, but it’s still not following the VirualService weights. Here’s my app:

import requests
import os
from flask import Flask, request

SERVICE_NAME = os.environ['SERVICE_NAME']
SERVICE_PORT = os.environ['SERVICE_PORT']


app = Flask(__name__)

@app.route('/reviews')
def hello():
    url = 'http://{0}:{1}/reviews/1'.format(SERVICE_NAME, SERVICE_PORT)
    print(url)

    headers = request.headers
    resp = requests.get(url, headers=headers)

    return resp.text


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

This is proxying to the exact same ‘reviews’ service that the functioning demo is, but I’m still getting back all 3 versions of the deployments, even when I have 100% of the weight pointing to a single version. Is there something I’m just missing with how things should work?

#2

And here’s the VirtualService and DestinationRule:

VirtualService

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  creationTimestamp: 2019-03-30T23:17:30Z
  generation: 1
  name: reviews
  namespace: test1234
  resourceVersion: "6781850"
  selfLink: /apis/networking.istio.io/v1alpha3/namespaces/test1234/virtualservices/reviews
  uid: fd6e4d69-5341-11e9-8145-020ddec3684a
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1
      weight: 0
    - destination:
        host: reviews
        subset: v2
      weight: 100

DestinationRule

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  creationTimestamp: 2019-03-30T23:17:30Z
  generation: 1
  name: reviews
  namespace: test1234
  resourceVersion: "6600474"
  selfLink: /apis/networking.istio.io/v1alpha3/namespaces/test1234/destinationrules/reviews
  uid: fd69579a-5341-11e9-8145-020ddec3684a
spec:
  host: reviews
  subsets:
  - labels:
      version: v1
    name: v1
  - labels:
      version: v2
    name: v2
#3

What version of Istio are you using? Also, try deleting the following block from your VirtualService:

    - destination:
        host: reviews
        subset: v1
      weight: 0

The yaml parsing library cannot distinguish between a weight set to 0 versus a weight not set at all. When weight is not specified, the default behavior is to route traffic to that destination block.

#4

I noticed your VirtualService and DestinationRule are created in the test1234 namespace - is this the same namespace your bookinfo services and your python flask app are deployed?