06-02 Traffic Shifting

Docker/Kubernetes workshop

06-02 Traffic Shifting

The examples are based on the Istio setup guide.

After following the setup guide, to view the Bookinfo app webpage, run the following command and paste the output into your browser.

echo http://$GATEWAY_URL/productpage

Traffic shifting is used to migrate traffic from one service version to another. Istio achieves this by using the VirtualService resource to configure rules to route a percentage of traffic to a service.

Istio uses HTTPRouteDestination to route traffic. You specify a destination host and weight attribute. The destination is a network addressable service in the service registry. The weight is the percentage of traffic.

- destination:
    host: reviews
    subset: v1
  weight: 50
- destination:
    host: reviews
    subset: v3
  weight: 50

Exercise

Kiali

Before starting, set up Kiali to easily visualise traffic routes. Ignore this if you already set up Kiali in 06-01-featuretoggles.

Run

istioctl dashboard kiali

and login with the default username admin and default password admin.


  1. The traffic-shifting-v1.yaml file will route all traffic to reviews:v1: ``` kind: VirtualService metadata: name: reviews spec: hosts:
    • reviews http:
    • route:
    • destination: host: reviews subset: v1
      Apply the file:
      

      kubectl apply -f exercise/traffic-shifting-v1.yaml ``` - Open the BookInfo site in the browser.
      Notice that the reviews part of the page displays with no rating stars, no matter how many times you refresh. This is because you configured Istio to route all traffic for the reviews service to reviews:v1 and this version of the service does not access the star ratings service.

  1. The traffic-shifting-50-v3.yaml file will transfer 50% of the traffic from reviews:v1 to reviews:v3:
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
    - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1
      weight: 50
    - destination:
        host: reviews
        subset: v3
      weight: 50

Apply the file:

kubectl apply -f exercise/traffic-shifting-50-v3.yaml
  1. The traffic-shifting-v3.yaml file will route 100% of the traffic to reviews:v3: ``` kind: VirtualService metadata: name: reviews spec: hosts:
    • reviews http: - route:
    • destination: host: reviews subset: v3
      Apply the file:
      

      kubectl apply -f exercise/traffic-shifting-v3.yaml ```

Clean up

kubectl delete -f exercise/traffic-shifting-v1.yaml
kubectl delete -f exercise/traffic-shifting-50-v3.yaml
kubectl delete -f exercise/traffic-shifting-v3.yaml