Traffic Shifting

    A common use case is to migrate traffic gradually from an older version of a microservice to a new one. In Istio, you accomplish this goal by configuring a sequence of routing rules that redirect a percentage of traffic from one destination to another.

    In this task, you will use send 50% of traffic to and 50% to reviews:v3. Then, you will complete the migration by sending 100% of traffic to reviews:v3.

    Istio includes beta support for the Kubernetes Gateway API and intends to make it the default API for traffic management . The following instructions allow you to choose to use either the Gateway API or the Istio configuration API when configuring traffic management in the mesh. Follow instructions under either the Gateway API or Istio classic tab, according to your preference.

    Note that this document uses the Gateway API to configure internal mesh (east-west) traffic, i.e., not just ingress (north-south) traffic. Configuring internal mesh traffic is an experimental feature of the Gateway API, currently under development and pending . Make sure to install the experimental CRDs before using the Gateway API:

    • Setup Istio by following the instructions in the .

    • Deploy the Bookinfo sample application.

    • Review the concepts doc.

    1. To get started, run this command to route all traffic to the v1 version:

    1. $ kubectl apply -f @samples/bookinfo/networking/virtual-service-all-v1.yaml@

    Zip

    1. $ kubectl apply -f @samples/bookinfo/gateway-api/route-reviews-v1.yaml@
    1. Open the Bookinfo site in your browser. The URL is http://$GATEWAY_URL/productpage, where $GATEWAY_URL is the External IP address of the ingress, as explained in the doc.

      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 the version reviews:v1 and this version of the service does not access the star ratings service.

    2. Transfer 50% of the traffic from reviews:v1 to reviews:v3 with the following command:

    Zip

      1. Wait a few seconds for the new rules to propagate and then confirm the rule was replaced:
      1. $ kubectl get virtualservice reviews -o yaml
      2. kind: VirtualService
      3. ...
      4. spec:
      5. hosts:
      6. - reviews
      7. http:
      8. - route:
      9. - destination:
      10. host: reviews
      11. weight: 50
      12. - destination:
      13. host: reviews
      14. subset: v3
      1. With the current Envoy sidecar implementation, you may need to refresh the /productpage many times –perhaps 15 or more–to see the proper distribution. You can modify the rules to route 90% of the traffic to v3 to see red stars more often.

      2. Assuming you decide that the reviews:v3 microservice is stable, you can route 100% of the traffic to reviews:v3 by applying this virtual service:

      Zip

      1. $ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-v3.yaml@

      1. $ kubectl apply -f @samples/bookinfo/gateway-api/route-reviews-v3.yaml@
      1. Refresh the /productpage several times. Now you will always see book reviews with red colored star ratings for each review.

      In this task you migrated traffic from an old to new version of the reviews service using Istio’s weighted routing feature. Note that this is very different than doing version migration using the deployment features of container orchestration platforms, which use instance scaling to manage the traffic.

      With Istio, you can allow the two versions of the reviews service to scale up and down independently, without affecting the traffic distribution between them.

      For more information about version routing with autoscaling, check out the blog article .

      1. Remove the application routing rules:
      1. $ kubectl delete httproute reviews