You can create destination rules and virtual services for an Alibaba Cloud Service Mesh (ASM) gateway in a visualized manner without writing YAML files. This simplifies traffic management. This topic describes how to create traffic policies and routing rules for an ASM gateway in a visualized manner.

Prerequisites

Background information

You can create a traffic policy that specifies the load balancing and connection pool settings for a service in a visualized manner. In this example, the reviews service is used. After the traffic policy is created, a YAML file for a destination rule is automatically generated. You can create routing rules for a service to match specific content in a URL, such as /productpage and /login. In this example, the Bookinfo service is used. This way, you can access the Bookinfo service by using a URL that contains information such as /productpage.

Create a traffic policy

  1. Import an upstream service.
    Import the reviews service to the ASM gateway to associate the ASM gateway with the reviews service.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.
    4. On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane. On the page that appears, click the name of the ASM gateway to which you want to import the reviews service.
    5. On the details page of the ASM gateway, click Upstream Service in the left-side navigation pane.
    6. On the page that appears, click Import service.
    7. On the Import service page, select a namespace from the Namespace drop-down list. In the select service section, select the reviews service and click the Move icon icon to move the reviews service to the selected section. Then, click OK.
      Import service page
  2. Manage versions of the reviews service.
    Group instances of the reviews service by version. In this example, the versions of the reviews service are v1, v2, and v3.
    1. On the Upstream Service page, find the reviews service and click versions in the Actions column.
    2. On the versions page, click Add Subset. Set the Name parameter to v1. Then, click Add Label and set the Name parameter to version and the Value parameter to v1.
    3. Click Add Subset for a second time. Set the Name parameter to v2. Then, click Add Label and set the Name parameter to version and the Value parameter to v2.
    4. Click Add Subset for a third time. Set the Name parameter to v3. Then, click Add Label and set the Name parameter to version and the Value parameter to v3. Then, click Submit.
      versions page
  3. Create a traffic policy.
    1. On the Upstream Service page, find the reviews service and click Traffic Policy in the Actions column.
    2. On the Traffic Policy page, click Add Policy. Select Subset Level and select v3 from the Subset drop-down list. Turn on Load Balancing and select Simple. Then, set the Mode parameter to Random and click Submit.
      Traffic Policy page
  4. Optional: After the traffic policy is created, view the YAML file that is automatically generated for a destination rule.
    On the Upstream Service page, find the reviews service and click YAML in the Actions column to view the YAML file in the Preview panel.
    Note You can also choose Traffic Management > DestinationRule in the left-side navigation pane of the details page of the ASM instance. On the DestinationRule page, find the destination rule whose YAML file you want to view and click YAML in the Actions column. In the Edit panel, view the YAML file of the destination rule.
    apiVersion: networking.istio.io/v1beta1
    kind: DestinationRule
    metadata:
      name: reviews
      namespace: default
      labels:
        provider: asm
    spec:
      host: reviews
      subsets:
        - name: v1
          labels:
            version: v1
        - name: v2
          labels:
            version: v2
        - name: v3
          labels:
            version: v3
          trafficPolicy:
            loadBalancer:
              simple: RANDOM

Create routing rules

  1. Import an upstream service.
    Import the productpage service to the ASM gateway to associate the ASM gateway with the productpage service.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.
    4. On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane. On the page that appears, click the name of the ASM gateway to which you want to import the productpage service.
    5. On the details page of the ASM gateway, click Upstream Service in the left-side navigation pane.
    6. On the Upstream Service page, click Import service.
    7. On the Import Service page, select a namespace from the Namespace drop-down list. In the select service section, select the productpage service and click the Move icon icon to move the productpage service to the selected section. Then, click OK.
  2. Create routing rules.
    1. Create a routing rule to match a URL that contains /productpage.
      1. On the details page of the ASM gateway, click Route management in the left-side navigation pane. On the page that appears, click Create.
      2. In the set route detail step, set the parameters that are described in the following table, and then click Next. set route detail step
        Parameter Description
        route type The type of the traffic to be routed. In this example, the value is http.
        Namespace The namespace in which you create the routing rule. In this example, the value is default.
        Name The name of the routing rule. In this example, the value is productpage-route.
        description The description of the routing rule. In this example, the value is The routing rule used to match a URL that contains /productpage.
        priority The priority of the routing rule. A smaller value indicates a higher priority. If a URL matches multiple routing rules, the routing rule that has the highest priority takes precedence. In this example, the value is 3.
        Matching URI

        The content to be matched in a URL. Only requests with a URL that contains the specified content can be routed to the destination service.

        Turn on Matching URI and set the Method parameter to Exact and the Content parameter to /productpage.
        Note You can also click Add Header Matching Rule to configure settings for matching HTTP headers.
      3. In the set route destination step, click Add Route Destination, set the parameters that are described in the following table, and then click Next. set route destination step
        Parameter Description
        select upstream service The service to which the routing rule applies. In this example, the value is productpage.
        Subset The version of the service to which the routing rule applies.
        Weight The traffic weight of the destination service.
      4. In the advanced config step, turn on Fault Injection. After that, turn on Request Latency, set the Latency parameter to 4s and the Injection Percentage parameter to 100, and then click Next. advanced config step
      5. In the confirm route configuration step, confirm the information about the routing rule and click Create.
    2. Create a routing rule to match a URL that contains /static.
      1. On the Route management page, click Create.
      2. In the set route detail step, set the parameters that are described in the following table, and then click Next. static
        Parameter Description
        route type The type of the traffic to be routed. In this example, the value is http.
        Namespace The namespace in which you create the routing rule. In this example, the value is default.
        Name The name of the routing rule. In this example, the value is static.
        description The description of the routing rule. In this example, the value is The routing rule used to match a URL that contains /static.
        priority The priority of the routing rule. A smaller value indicates a higher priority. If a URL matches multiple routing rules, the routing rule that has the highest priority takes precedence. In this example, the value is 0.
        Matching URI

        The content to be matched in a URL. Only requests with a URL that contains the specified content can be routed to the destination service.

        Turn on Matching URI and set the Method parameter to Prefix and the Content parameter to /static.

      3. The subsequent steps for creating the static routing rule are the same as those for creating the productpage-route routing rule. For more information, see the Create a routing rule to match a URL that contains /productpage section in this topic.
    3. Create a routing rule to match a URL that contains /login.
      1. On the Route management page, click Create.
      2. In the set route detail step, set the parameters that are described in the following table, and then click Next. login
        Parameter Description
        route type The type of the traffic to be routed. In this example, the value is http.
        Namespace The namespace in which you create the routing rule. In this example, the value is default.
        Name The name of the routing rule. In this example, the value is login.
        description The description of the routing rule. In this example, the value is The routing rule used to match a URL that contains /login.
        priority The priority of the routing rule. A smaller value indicates a higher priority. If a URL matches multiple routing rules, the routing rule that has the highest priority takes precedence. In this example, the value is 0.
        Matching URI

        The content to be matched in a URL. Only requests with a URL that contains the specified content can be routed to the destination service.

        Turn on Matching URI and set the Method parameter to Prefix and the Content parameter to /login.

      3. The subsequent steps for creating the login routing rule are the same as those for creating the productpage-route routing rule. For more information, see the Create a routing rule to match a URL that contains /productpage section in this topic.
    4. Create a routing rule to match a URL that contains /logout.
      1. On the Route management page, click Create.
      2. In the set route detail step, set the parameters that are described in the following table, and then click Next. logout
        Parameter Description
        route type The type of the traffic to be routed. In this example, the value is http.
        Namespace The namespace in which you create the routing rule. In this example, the value is default.
        Name The name of the routing rule. In this example, the value is logout.
        description The description of the routing rule. In this example, the value is The routing rule used to match a URL that contains /logout.
        priority The priority of the routing rule. A smaller value indicates a higher priority. If a URL matches multiple routing rules, the routing rule that has the highest priority takes precedence. In this example, the value is 0.
        Matching URI

        The content to be matched in a URL. Only requests with a URL that contains the specified content can be routed to the destination service.

        Turn on Matching URI and set the Method parameter to Prefix and the Content parameter to /logout.

      3. The subsequent steps for creating the logout routing rule are the same as those for creating the productpage-route routing rule. For more information, see the Create a routing rule to match a URL that contains /productpage section in this topic.
    5. Create a routing rule to match a URL that contains /api/v1/products.
      1. On the Route management page, click Create.
      2. In the set route detail step, set the parameters that are described in the following table, and then click Next. product
        Parameter Description
        route type The type of the traffic to be routed. In this example, the value is http.
        Namespace The namespace in which you create the routing rule. In this example, the value is default.
        Name The name of the routing rule. In this example, the value is products-route.
        description The description of the routing rule. In this example, the value is The routing rule used to match a URL that contains /api/v1/products.
        priority The priority of the routing rule. A smaller value indicates a higher priority. If a URL matches multiple routing rules, the routing rule that has the highest priority takes precedence. In this example, the value is 0.
        Matching URI

        The content to be matched in a URL. Only requests with a URL that contains the specified content can be routed to the destination service.

        Turn on Matching URI and set the Method parameter to Prefix and the Content parameter to /api/v1/products.

      3. The subsequent steps for creating the products-route routing rule are the same as those for creating the productpage-route routing rule. For more information, see the Create a routing rule to match a URL that contains /productpage section in this topic.
  3. Check whether the routing rules take effect.
    1. In the address bar of your browser, enter http://{IP address of the ASM gateway}/productpage. In this example, Google Chrome is used.
      The following figure shows the sample page that appears. Sample Bookinfo page
    2. In the upper-right corner of the Bookinfo page, click Sign in.
    3. On the page that appears, enter your account and password and click Sign in.
      The following figure shows the page of the Bookinfo service after logon. Access the Bookinfo service

      You can also use a URL that contains /logout, /static, or /api/v1/products to access the Bookinfo service. The corresponding procedures are omitted in this section.

    4. In the upper-right corner of Google Chrome, click the More icon and choose More Tools > Developer Tools.
    5. Refresh the page whose address is http://{IP address of the ASM gateway}/productpage.
      On the Network tab, a delay of about 4 seconds is reported. Network tab
  4. Optional: After the routing rules are created, view the YAML files that are automatically generated for the corresponding virtual services.
    On the details page of the ASM instance, choose Traffic Management > VirtualService in the left-side navigation pane. On the VirtualService page, find the virtual service whose YAML file you want to view and click YAML in the Actions column. In the Edit panel, view the automatically generated YAML file.

Related operations

View the details of an imported service

View the details of an imported service, such as the settings of the sidecar proxy injection and the region.

  1. Log on to the ASM console.
  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.
  4. On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane. On the page that appears, click the name of the ASM gateway for which you want to view service details.
  5. On the details page of the ASM gateway, click Upstream Service in the left-side navigation pane.
  6. On the Upstream Service page, find the service whose details you want to view and click service details in the Actions column.
    On the details page of the service, view the details of the service, such as the settings of the sidecar proxy injection and the region.

Disable a routing rule

You can disable a routing rule so that this routing rule no longer takes effect.
Note You can enable a disabled routing rule by performing the following steps:

On the Route management page, find the routing rule that you want to enable and click online in the Actions column. In the message that appears, click OK.

  1. Log on to the ASM console.
  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.
  4. On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane. On the page that appears, click the name of the ASM gateway for which you want to disable a routing rule.
  5. On the details page of the ASM gateway, click Route management in the left-side navigation pane.
  6. On the page that appears, find the routing rule named login and click offline in the Actions column.
  7. In the message that appears, click OK.
  8. Verify that the disabled routing rule no longer takes effect.
    1. In the address bar of Google Chrome, enter http://{IP address of the ASM gateway}/productpage.
    2. In the upper-right corner of the Bookinfo page, click Sign in.
    3. On the page that appears, enter your account and password and click Sign in.

      A 404 error occurs, which indicates that the login routing rule is disabled and no longer takes effect.