Request Routing and Canary Testing

In this chapter, we are going to get our hands on some of the traffic management capabilities of Istio.

Apply default destination rules


Before we start playing with Istio's traffic management capabilities, we need to define the available versions of the deployed services. In Istio parlance, versions are called subsets. Subsets are defined in destination rules.

Run the following in the custom yaml section to create default destination rules for the Bookinfo services:

1apiVersion: networking.istio.io/v1alpha3
2kind: DestinationRule
3metadata:
4 name: productpage
5spec:
6 host: productpage
7 subsets:
8 - name: v1
9 labels:
10 version: v1
11---
12
13apiVersion: networking.istio.io/v1alpha3
14kind: DestinationRule
15metadata:
16name: reviews
17spec:
18host: reviews
19subsets: - name: v1
20labels:
21version: v1 - name: v2
22labels:
23version: v2 - name: v3
24labels:
25version: v3
26
27---
28
29apiVersion: networking.istio.io/v1alpha3
30kind: DestinationRule
31metadata:
32name: ratings
33spec:
34host: ratings
35subsets: - name: v1
36labels:
37version: v1 - name: v2
38labels:
39version: v2 - name: v2-mysql
40labels:
41version: v2-mysql - name: v2-mysql-vm
42labels:
43version: v2-mysql-vm
44
45---
46
47apiVersion: networking.istio.io/v1alpha3
48kind: DestinationRule
49metadata:
50name: details
51spec:
52host: details
53subsets: - name: v1
54labels:
55version: v1 - name: v2
56labels:
57version: v2
58
59---

Using Meshery, navigate to the Istio management page:

  1. Enter default in the Namespace field.
  2. Click the (+) icon on the Apply Service Mesh Configuration card and select Bookinfo subsets from the list.

This will deploy the destination rules for all the Book info services defining their subsets. Verify the destination rules created by using the command below:

1kubectl get destinationrules
2
3
4kubectl get destinationrules -o yaml

Configure the default route for all services to V1


As part of the bookinfo sample app, there are multiple versions of reviews service. When we load the /productpage in the browser multiple times we have seen the reviews service round robin between v1, v2 or v3. As the first exercise, let us first restrict traffic to just V1 of all the services.

Using Meshery, navigate to the Istio management page:

  1. Enter default in the Namespace field.
  2. Click the (+) icon on the Apply Custom Configuration card and paste the configuration below.

To view the applied rule:

1kubectl get virtualservice

To take a look at a specific one:

1kubectl get virtualservice reviews -o yaml

Please note: In the place of the above command, we can either use kubectl or istioctl.

Config:

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13---

Now when we reload the /productpage several times, we will ONLY be viewing the data from v1 of all the services, which means we will not see any ratings (any stars).

Content-based routing


Let's replace our first rules with a new set. Enable the `ratings` service for a user `jason` by routing `productpage` traffic to `reviews` v2:

Using Meshery, navigate to the Istio management page:

  1. Enter default in the Namespace field.
  2. Click the (+) icon on the Apply Custom Configuration card and paste the configuration below.

This will update the existing virtual service definition for reviews to route all traffic for user jason to review V2.

In a few, we should be able to verify the virtual service by using the command below:

1kubectl get virtualservice reviews -o yaml

Config:

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - match:
10 - headers:
11 end-user:
12 exact: jason
13 route:
14 - destination:
15 host: reviews
16 subset: v2
17 - route:
18 - destination:
19 host: reviews
20 subset: v1
21---

Now if we login as your jason, you will be able to see data from reviews v2. While if you NOT logged in or logged in as a different user, you will see data from reviews v1.

Canary Testing - Traffic Shifting


Canary testing w/50% load

To start canary testing, let's begin by transferring 50% of the traffic from reviews:v1 to reviews:v3 with the following command:

Using Meshery, navigate to the Istio management page:

  1. Enter default in the Namespace field.
  2. Click the (+) icon on the Apply Custom Configuration card and paste the configuration below.

This will update the existing virtual service definition for reviews to route 50% of all traffic to review V3.

In a few, we should be able to verify the virtual service by using the command below:

1kubectl get virtualservice reviews -o yaml

Config:

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13 weight: 50
14 - destination:
15 host: reviews
16 subset: v3
17 weight: 50
18---

Now, if we reload the /productpage in your browser several times, you should now see red-colored star ratings approximately 50% of the time.

Shift 100% to v3

When version v3 of the reviews microservice is considered stable, we can route 100% of the traffic to reviews:v3:

Using Meshery, navigate to the Istio management page:

  1. Enter default in the Namespace field.
  2. Click the (+) icon on the Apply Custom Configuration card and paste the configuration below.

This will update the existing virtual service definition for reviews to route 100% of all traffic to review V3.

In a few, we should be able to verify the virtual service by using the command below:

1kubectl get virtualservice reviews -o yaml

Config:

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v3
13---

Now, if we reload the /productpage in your browser several times, you should now see red-colored star ratings 100% of the time.


Alternative: Manual installation

Follow these steps if the above steps did not work

Default destination rules

Run the following command to create default destination rules for the Bookinfo services:

1kubectl apply -f samples/bookinfo/networking/destination-rule-all-mtls.yaml

Route all traffic to version V1 of all services

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

Route all traffic to version V2 of reviews for user Jason

1kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

Route 50% of traffic to version V3 of reviews service

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

Route 100% of traffic to version V3 of reviews service

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

NEXT CHAPTER

Getting Started

Layer5, the cloud native management company

An empowerer of engineers, Layer5 helps you extract more value from your infrastructure. Creator and maintainer of cloud native standards. Maker of Meshery, the cloud native manager.