Version-based traffic routing allows you to split traffic between different service versions based on specified weights. This technique is ideal for canary releases and A/B testing. This topic demonstrates how to use Istio resources for this purpose.
Prerequisites
Step 1: Create a Gateway
A Gateway defines a load balancer at the edge of the service mesh for inbound or outbound HTTP/TCP connections. This step shows how to create a Gateway and bind it to the ingress gateway.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create.
-
On the Create page, configure the following parameters and click Create.
For more information about the parameters, see Gateway.
Parameter
Description
Basic Information
Set Namespaces to default and Name to bookinfo-gateway.
Gateway Pod Selector
Set Key to istio and Value to ingressgateway.
Exposed Service
Set Name to http, Port to 80, Protocol to HTTP, and Hosts to *.
The YAML configuration for the Gateway is as follows.
The following YAML file shows the Gateway that corresponds to the preceding configurations.
Step 2: Create a VirtualService
The VirtualService routes requests to the Bookinfo application through the following paths: /productpage, /static, /login, /logout, and /api/v1/products.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create.
-
On the Create page, configure the following parameters and click Create.
For more information about the parameters, see Virtual Service.
Parameter
Description
Basic Information
Namespaces
In this example, select default.
Name
Enter a custom name for the VirtualService.
Gateways
-
Enable Apply To specific Gateways, and then click Select the name of the Gateway.
-
In the Select the name of the Gateway dialog box, select bookinfo-gateway, click the
icon, and then click OK. -
Disable Apply To All Sidecars.
Hosts
Click Select the gateway domain name which VirtualService belongs to. In the Select the gateway domain name which VirtualService belongs to dialog box, select *, click the
icon, and then click OK.HTTP Route
Name
Click HTTP Route, click Add Route, and then enter a custom Name.
Request matching rules
Click Add Request Matching Rule repeatedly to configure the following five rules:
-
Enable Matching request URI, set Method to Exact, and set Content to /productpage.
-
Enable Matching request URI, set Method to Prefix, and set Content to /static.
-
Enable Matching request URI, set Method to Exact, and set Content to /login.
-
Enable Matching request URI, set Method to Exact, and set Content to /logout.
-
Enable Matching request URI, set Method to Prefix, and set Content to /api/v1/products.
Route destination
Click Add Route Destination, set Host to productpage, and set Port to 9080.
The following YAML file shows the VirtualService that corresponds to the preceding configurations.
-
Step 3: Access the Bookinfo application
-
Get the service address of the ingress gateway.
ASM console
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, find the Service address.
ACK console
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
At the top of the Hosts page, select Namespaces from the Namespace drop-down list. In the External IP column, find the IP address associated with port 80 for the istio-ingressgateway service.
-
-
In the address bar of your browser, enter http://{IP address of the ingress gateway}/productpage and refresh the page several times to observe the default round-robin routing.
Each time you refresh the page, you access one of the v1, v2, or v3 versions of the reviews service. You will notice that traffic to the three versions of the reviews service is distributed in an approximately 1:1:1 ratio.
The reviews-v1 page displays only text reviews with no star ratings, the reviews-v2 page displays black star ratings, and the reviews-v3 page displays red star ratings.
Step 4: Create version-based routing rules
-
Create a DestinationRule to define version-based subsets (v1, v2, and v3) for the reviews service.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create.
-
On the Create page, configure the following parameters and click Create.
For more information about the parameters, see Destination Rule.
Parameter
Description
Basic Information
Set Namespaces to default, enter a custom Name for the DestinationRule, and set Host to reviews.
Service Version (Subset)
Click Service Version (Subset). Click Add Service Version (Subset) repeatedly to configure the following three subsets.
-
Subset 1: Set Name to v1. Click Add Label, set Key to version, and set Value to v1.
-
Subset 2: Set Name to v2. Click Add Label, set Key to version, and set Value to v2.
-
Subset 3: Set Name to v3. Click Add Label, set Key to version, and set Value to v3.
The following YAML file shows the DestinationRule that corresponds to the preceding configurations.
-
-
-
Create a VirtualService to route traffic to the reviews service based on the following weights: 10% to v1, 40% to v2, and 50% to v3.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create.
-
On the Create page, configure the following parameters and click Create.
Parameter
Description
Basic Information
Namespaces
In this example, select default.
Name
Enter a custom name for the VirtualService.
Gateways
Enable Apply To All Sidecars.
Hosts
Click Add Host. In the Add Host dialog box, set Namespaces to default. In the Add Host section, select the reviews service, click the
icon, and then click OK.HTTP Route
Name
Click HTTP Route, click Add Route, and then enter a custom Name.
Route destination
Click Add Route Destination repeatedly to configure the following three route destinations.
-
Set Host to reviews, the version to v1, and the weight to 10.
-
Set Host to reviews, Subset to v2, and Weight to 40.
-
Set Host to reviews, Subset to v3, and Weight to 50.
The following YAML file shows the VirtualService that corresponds to the preceding configurations.
The YAML for the VirtualService is as follows.
-
-
Step 5: Verify version-based routing
In the address bar of your browser, enter http://{IP address of the ingress gateway}/productpage and refresh the page about 10 times.
If traffic is distributed to the v1, v2, and v3 service versions in an approximate 1:4:5 ratio, the weighted routing rules are working correctly.