This task shows you how to gradually migrate traffic from an old to new version of a service.
With Istio, we can migrate the traffic in a gradual fashion by using a sequence of rules
with weights less than 100 to migrate traffic in steps, for example 10, 20, 30, … 100%.
For simplicity this task will migrate the traffic from
reviews:v3 in just
two steps: 50%, 100%.
Before you begin
Setup Istio by following the instructions in the Installation guide.
Deploy the Bookinfo sample application.
Weight-based version routing
Set the default version for all microservices to v1.
$ istioctl create -f @samples/bookinfo/routing/route-rule-all-v1.yaml@
Confirm v1 is the active version of the
reviewsservice by opening http://$GATEWAY_URL/productpage in your browser.
You should see the Bookinfo application productpage displayed. Notice that the
productpageis displayed with no rating stars since
reviews:v1does not access the ratings service.
First, transfer 50% of the traffic from
reviews:v3with the following command:
$ istioctl replace -f @samples/bookinfo/routing/route-rule-reviews-50-v3.yaml@
Confirm the rule was replaced:
$ istioctl get virtualservice reviews -o yaml apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: reviews ... spec: hosts: - reviews http: - route: - destination: host: reviews subset: v1 weight: 50 - route: - destination: host: reviews subset: v3 weight: 50
productpagein your browser and you should now see red colored star ratings approximately 50% of the time.
With the current Envoy sidecar implementation, you may need to refresh the
productpagevery many times to see the proper distribution. It may require 15 refreshes or more before you see any change. You can modify the rules to route 90% of the traffic to v3 to see red stars more often.
When version v3 of the
reviewsmicroservice is considered stable, we can route 100% of the traffic to
$ istioctl replace -f @samples/bookinfo/routing/route-rule-reviews-v3.yaml@
You can now log into the
productpageas any user and you should always see book reviews with red colored star ratings for each review.
Understanding what happened
In this task we 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 version migration using deployment features
of container orchestration platforms, which use instance scaling to manage the traffic.
With Istio, we can allow the two versions of the
reviews service to scale up and down independently,
without affecting the traffic distribution between them.
For more about version routing with autoscaling, check out Canary Deployments using Istio.
Remove the application routing rules.
$ istioctl delete -f @samples/bookinfo/routing/route-rule-all-v1.yaml@
If you are not planning to explore any follow-on tasks, refer to the Bookinfo cleanup instructions to shutdown the application.
- Learn more about request routing.