Service Mesh (ASM) provides an intuitive graphical user interface (GUI) for gateways. You can create destination rules and virtual services directly in the console without writing YAML files, simplifying traffic management. This topic describes how to create traffic policies and routing rules by using the GUI.
Prerequisites
-
Automatic sidecar injection is enabled for the namespace. For more information, see Enable automatic injection.
An ingress gateway is deployed. For more information, see Create an ingress gateway.
An application is deployed in the cluster that is added to the ASM instance. For more information, see Deploy an application to an ASM-associated cluster.
-
You have obtained the address of the ASM gateway. For more information, see Obtain the address of an ingress gateway.
Overview
This topic uses the reviews service as an example to show how to configure traffic policies, such as load balancing and connection pools, by using the GUI. After a traffic policy is created, a YAML file for the corresponding destination rule is automatically generated. This topic also shows how to create routing rules for paths in the Bookinfo service, such as /productpage and /login. This allows you to access the Bookinfo service through paths such as /productpage.
Create a domain
-
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, click the name of the target gateway. In the navigation pane on the left of the Gateway Overview page, click Domain/Certificate.
-
On the Add domain page, configure the following parameters and click Create.
Parameter
Example
Domain
*
Protocol
HTTP
Namespaces
default
Port Name
http
Port
80
Import an upstream service
Import upstream services into the ASM gateway.
-
On the Ingress Gateway page, click the name of the target gateway. In the navigation pane on the left of the Gateway Overview page, click Upstream Service.
-
On the Upstream Service page, click Import service. On the Import service page, select a Namespaces, select the reviews and productpage services, click the
icon, and then click Confirm.
Create a traffic policy
-
Manage service versions.
This example groups the instances of the reviews service into three versions: v1, v2, and v3.
-
On the Upstream Service page, find the reviews service and click versions in the Operator column.
-
On the versions page, click Add Service Version (Subset), set Name to v1, click Add Label, set Key to version, and set Value to v1.
-
Click Add Service Version (Subset), set Name to v2, click Add Label, set Key to version, and set Value to v2.
-
Click Add Service Version (Subset) again, set Name to v3, click Add Label, set Key to version, and set Value to v3. Then, click Create.
-
-
Create a traffic policy.
-
On the Upstream Service page, find the reviews service and click traffic policy in the Operator column.
-
On the traffic policy page, click Add Policy, select Subset Level, and select the v3 version. Turn on the Load Balancing switch, select Simple, set Mode to Random, and then click Submit.
-
-
(Optional) View the YAML file for the destination rule that is generated when you create the traffic policy.
On the Upstream Service page, find the reviews service and click View YAML in the Operator column. In the Preview dialog box, view the YAML file. After you confirm the content, click Confirm.
NoteAlternatively, in the navigation pane on the left of the mesh details page, choose . On the DestinationRule page, find the target destination rule and click View YAML in the Operator column. In the Edit dialog box, view the generated YAML file for the destination rule.
Create routing rules
-
Create routing rules.
-
Create a routing rule for
/productpage.-
In the navigation pane on the left of the Gateway Overview page, click Route management, and then click Create.
-
In the set route detail wizard, configure the parameters and click Next.
Parameter
Example
route type
For this example, select http.
Namespaces
For this example, select default.
route name
For this example, enter
productpage-route.description
For this example, enter
productpage route.priority
For this example, enter
3.NoteRouting rules are prioritized by number. A smaller number indicates a higher priority. If a request URI matches multiple routing rules, ASM applies the one with the highest priority.
Matching rules
Configure URL matching. Only requests from URLs that meet the requirements can be routed to the destination service.
Turn on the Matching request URI switch. Set Method to Exact and Content to
/productpage.NoteYou can also click Add Header Matching Rule to set header matching.
-
In the set route destination wizard, configure the parameters, and then click Next.
Parameter
Example
select upstream service
Select the service to which the routing rule applies. For this example, select productpage.
Port
Optional. The port exposed by the upstream service. This is required if the service exposes more than one port. For this example, leave this parameter empty.
Subset
Specifies the service version (subset) to which the routing rule applies. Leave this field empty for this example.
Weight
Specifies the traffic weight for the destination service. Leave this field empty for this example.
-
In the advanced config wizard, turn on the Fault Injection switch. Then, turn on the Request Latency switch, set Latency to 4s and Injection Percentage to 100, and then click Create.
-
-
Create a routing rule for
/static.-
On the Route management page, click Create.
-
In the set route detail wizard, configure the parameters and click Next.
Parameter
Example
route type
For this example, select http.
Namespaces
For this example, select default.
route name
For this example, enter
static.description
For this example, enter
static resource.priority
For this example, enter
0.Matching rules
Configure URL matching. Only requests from URLs that meet the requirements can be routed to the destination service.
Turn on the Matching request URI switch. Set Method to Prefix and Content to
/static. -
The steps for creating the
/staticroute are the same as those for the/productpageroute. For details, see Create the productpage route.
-
-
Create a routing rule for
/login.-
On the Route management page, click Create.
-
In the set route detail wizard, configure the parameters, and then click Next.
Parameter
Example
route type
For this example, select http.
Namespaces
For this example, select default.
route name
For this example, enter
login.description
For this example, enter
login request route.priority
For this example, enter
0.Matching rules
Configure URL matching. Only requests from URLs that meet the requirements can be routed to the destination service.
Turn on the Matching request URI switch. Set Method to Prefix and Content to
/login. -
The subsequent steps to create the
/loginroute are the same as those for the/productpageroute. For the detailed steps, see Create the productpage route.
-
-
Create a routing rule for
/logout.-
On the Route management page, click Create.
-
In the set route detail wizard, configure the parameters, and then click Next.
Parameter
Example
route type
For this example, select http.
Namespaces
For this example, select default.
route name
For this example, enter
logout.description
For this example, enter
logout route.priority
For this example, enter
0.Matching rules
Configure URL matching. Only requests from URLs that meet the requirements can be routed to the destination service.
Turn on the Matching request URI switch. Set Method to Prefix and Content to /logout.
-
The subsequent steps to create the /logout route are the same as those for the /productpage route. For the detailed steps, see Create the productpage route.
-
-
Create a routing rule for
/api/v1/products.-
On the Route management page, click Create.
-
In the set route detail wizard, configure the parameters, and then click Next.
Parameter
Description
route type
For this example, select http.
Namespaces
For this example, select default.
route name
For this example, enter
products-route.description
For this example, enter
product information.priority
For this example, enter
0.Matching rules
Configure URL matching. Only requests from URLs that meet the requirements can be routed to the destination service.
Turn on the Matching request URI switch. Set Method to Prefix and Content to
/api/v1/products. -
The subsequent steps to create the
/api/v1/productsroute are the same as those for creating the/productpageroute. For details, see Create the productpage route.
-
-
-
Verify the routing rules.
-
In the address bar of your browser, enter
http://{IP address of the ingress gateway}/productpage.The product page of the Bookinfo sample application is displayed. It includes a summary of the book The Comedy of Errors, Book Details (such as genre, page count, publisher, and language), and Book Reviews (including ratings and comments). This confirms that the routing rule is working.
-
In the upper-right corner of the Bookinfo page, click Sign in.
-
On the Please sign in page, enter any username and password, and click Sign in.
You can successfully sign in to Bookinfo. After you sign in, the product page of the Bookinfo application is displayed. The username default is shown in the upper-right corner, and the book details and reviews are displayed correctly. This indicates that the service is accessible.
To verify other routes, you can also access the Bookinfo service by using paths such as /logout, /static, and /api/v1/products.
-
Open your browser's developer tools and switch to the network tab.
-
Refresh the page.
A delay of about 4 seconds is observed. In the Network panel of your browser's developer tools, the
productpagerequest takes about 4.21 seconds, while other static resources such as CSS, JS, and font files take 0 ms. This confirms that the fault injection policy is working.
-
-
(Optional) View the YAML file of the virtual service that is generated after the routing rules are created.
-
On the details page of the ASM instance, choose in the left-side navigation pane.
-
On the Virtual Service page, find the target virtual service and click View YAML in the Operator column.
-
In the Edit dialog box, view the generated YAML file for the virtual service. After you confirm the content, click OK.
-
Related operations
View service details
View details of an imported service, such as its sidecar injection status and region.
-
On the Ingress Gateway page, click the name of the target gateway. In the navigation pane on the left of the Gateway Overview page, click Upstream Service.
-
On the Upstream Service page, find the target service and click service details in the Operator column. On the service details page, view details of the service, such as its sidecar injection status and region.
Take routing rule offline
You can deactivate a routing rule by taking it offline.
-
On the Ingress Gateway page, click the name of the target gateway.
-
In the navigation pane on the left of the Gateway Overview page, click Route management.
-
On the Route management page, find the target routing rule and click offline in the Operator column.
-
In the Confirm dialog box, click OK.
-
Verify that the routing rule is offline.
-
In the address bar of your browser, enter
http://{IP address of the ingress gateway}/productpage. -
In the upper-right corner of the Bookinfo page, click Sign in.
-
On the Please sign in page, enter any username and password, and click Sign in.
A "page not found" error appears, which confirms that the routing rule is inactive.
NoteTo reactivate the rule, bring it online:
On the Route management page, find the target routing rule and click online in the Operator column. In the Confirm dialog box, click OK.
-