Intelligent Routing with Istio on Alibaba Cloud Container Service for Kubernetes

The previous article uses an official example to demonstrate how to deploy applications in this Istio environment. Based on this example, this article will explain how to use Istio functions, such as traffic routing, fault injection, rate limiting, and traffic shifting.

To quickly review this official example, visit https://istio.io/docs/guides/bookinfo. As shown below, the example application is composed of four separate microservices that are compiled in different languages. These services are not dependent on Istio.

Request Routing

Set the Default Version of All Microservices to v1

istioctl create -f samples/bookinfo/routing/route-rule-all-v1.yaml

You can run the following command to display all the routing rules that have been created:

istioctl get virtualservices -o yaml

As routing rules are distributed to the proxies in an asynchronized manner, these rules are synchronized to all pods after a period of time.Therefore, you need to wait for a few seconds and then try to access the application.

Open the URL of the BookInfo application in the browser: http://{EXTERNAL-IP}/productpage.

For more information on getting the EXTERNAL-IP, refer to the previous article.

The productpage of the BookInfo application is displayed, where the review information without stars is displayed, because the reviews v1 service does not call the ratings service.

Route Requests from a Specific User to Reviews v2

kubectl replace -f samples/bookinfo/routing/route-rule-reviews-test-v2.yaml

Run the following command to confirm that the rule is created:

kubectl  get virtualservice reviews -o yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
clusterName: ""
creationTimestamp: 2018-06-04T10:49:53Z
generation: 0
name: reviews
namespace: default
resourceVersion: "2596548"
selfLink: /apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/reviews
uid: 03528fd9-67e5-11e8-af82-00163e0c19c2
spec:
hosts:
- reviews
http:
- match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v1

After confirming that the rule is created, open the URL of the BookInfo application in the browser: http://{EXTERNAL-IP}/productpage.

Log on to the productpage as user “jason”. The rating information should be displayed at the bottom of each review record.

The mechanism is as follows: Use Istio to route all the requests to reviews v1 service. Then, configure a routing rule, which selectively routes requests to the reviews v2 service based on the request header, for example, the user’s cookie.

Fault Injection

HTTP Delay

kubectl replace -f samples/bookinfo/routing/route-rule-ratings-test-delay.yaml

After confirming that the rule is created, open the URL of the BookInfo application in the browser: http://{EXTERNAL-IP}/productpage.

Log on to the productpage as user “jason”. The following page should be displayed:

The reviews service fails because the timeout between the productpage and reviews services is shorter than the timeout between the reviews and ratings services, that is, (3 seconds + 1 retry = 6 seconds) is shorter than 10 seconds.Bugs like this can occur in typical enterprise applications where different teams develop different microservices independently.Istio’s fault injection rules help you identify such anomalies without impacting end users.

HTTP Abort

kubectl replace -f samples/bookinfo/routing/route-rule-ratings-test-abort.yaml

After confirming that the rule is created, open the URL of the BookInfo application in the browser: http://{EXTERNAL-IP}/productpage.

Log on to the productpage as user “jason”. The following page should be displayed:

Traffic Shifting

First, set the default version of all microservices to v1.

kubectl replace -f samples/bookinfo/routing/route-rule-all-v1.yaml

Second, run the following command to route 50% of requests from the reviews v1 service to the reviews v3 service:

kubectl replace -f samples/bookinfo/routing/route-rule-reviews-50-v3.yaml

Refresh the productpage for multiple times in the browser. You have a 50% probability to see the review content marked with red stars on the page.

Note that this method is completely different from using the deployment feature of the container orchestration platform for version migration.The container orchestration platform uses the instance scaling method to manage the traffic.In contrast, Istio allows two versions of the reviews service to scale up and down independently, without affecting the traffic distribution between them.

Summary

This article series introduces Istio and its core components, as well as describes how to quickly build an Istio open platform for connecting, managing, and securing microservices on the basis of Alibaba Cloud Container Service for Kubernetes. These articles also use an official example to demonstrate how to deploy an application in the Istio environment; how to configure intelligent routing and distributed tracing; and how to configure Istio functions of collecting, querying, and visualizing the telemetry data.

To review these articles, see:

  1. Using Istio on Alibaba Cloud Container Service for Kubernetes
  2. Go through Istio Features with Samples on Alibaba Cloud Container Service for Kubernetes
  3. Intelligent Routing with Istio on Alibaba Cloud Container Service for Kubernetes
  4. Distributed Tracking with Istio on Alibaba Cloud Container Service for Kubernetes
  5. Telemetry Data Collection, Query, and Visualization with Istio on Alibaba Cloud Container Service for Kubernetes
  6. Fault Diagnosis and Detection using Istio within Alibaba Cloud Container Service for Kubernetes
  7. Observability Analysis using Istio and Kiali within Alibaba Cloud Container Service for Kubernetes

Reference:

https://www.alibabacloud.com/blog/intelligent-routing-with-istio-on-alibaba-cloud-container-service-for-kubernetes_593924?spm=a2c41.11962065.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.