All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure traffic routing for an ASM gateway

Last Updated:Mar 07, 2024

You can create destination rules and virtual services for a Service Mesh (ASM) gateway on a graphical user interface (GUI) without writing YAML files. This simplifies traffic management. This topic describes how to create traffic policies and routing rules for an ASM gateway on a GUI.

Prerequisites

Background information

You can create a traffic policy that specifies the load balancing and connection pool settings for a service on a GUI. 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. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

    3. On the Ingress Gateway page, click the name of the ASM gateway to which you want to import the reviews service.

    4. In the left-side navigation pane of the Gateway overview page, click Upstream Service.

    5. On the Gateway upstream services page, click Import service.

    6. On the Import service page, select a namespace from the Namespace drop-down list. In the select service box, select the reviews service and click the 上游服务 icon to move the reviews service to the selected box. Then, click Submit.

      导入服务

  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 Gateway upstream services page, find the reviews service and click versions in the Actions column.

    2. On the versions page, click Add Service Version (Subset). Set the Name parameter to v1. Then, click Add Label and set the Key parameter to version and the Value parameter to v1.

    3. Click Add Service Version (Subset) again. Set the Name parameter to v2. Then, click Add Label and set the Key parameter to version and the Value parameter to v2.

    4. Click Add Service Version (Subset) again. Set the Name parameter to v3. Then, click Add Label and set the Key parameter to version and the Value parameter to v3. Then, click Create.

  3. Create a traffic policy.

    1. On the Gateway upstream services 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.

      流量策略

  4. (Optional) After the traffic policy is created, view the YAML file that is automatically generated for a destination rule.

    On the Gateway upstream services page, find the reviews service and click YAML in the Actions column to view the YAML file in the Preview dialog box. After you confirm the correctness of the YAML file, click Submit.

    Note

    You can also choose Traffic Management Center > DestinationRule in the left-side navigation pane on the details page of the ASM instance. On the DestinationRule page, find the rule whose YAML file you want to view and click YAML in the Actions column. In the Edit dialog box, view the YAML file of the destination rule.

    Show the YAML file

    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. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

    3. On the Ingress Gateway page, click the name of the ASM gateway to which you want to import the productpage service.

    4. In the left-side navigation pane of the Gateway overview page, click Upstream Service.

    5. On the Gateway upstream services page, click Import service.

    6. On the Import service page, select a namespace from the Namespace drop-down list. In the select service box, select the productpage service and click the 上游服务 icon to move the productpage service to the selected box. Then, click Submit.

  2. Create routing rules.

    1. Create a routing rule to match a URL that contains /productpage.

      1. In the left-side navigation pane of the Gateway overview page, click Route management. 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.

        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 productpage routing.

        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 Rule

        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 request URI, set Method to Exact and Content 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, set the parameters that are described in the following table, and then click Next.

        Parameter

        Description

        select upstream service

        The service to which the routing rule applies. In this example, the value is productpage.

        Port

        (Optional) The port through which the routing rule connects to the upstream service. The upstream service may expose multiple ports. In this case, specify a port.

        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 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.

        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 static resource.

        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 Rule

        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 request URI, set Method to Prefix and Content to /static.

      3. The subsequent steps for creating a routing rule to match a URL that contains /static are the same as those for creating a routing rule to match a URL that contains /productpage. 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.

        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 login request routing.

        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 Rule

        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 request URI and set the Method parameter to Prefix and the Content parameter to /login.

      3. The subsequent steps for creating a routing rule to match a URL that contains /login are the same as those for creating a routing rule to match a URL that contains /productpage. 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.

        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 logout route.

        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 Rule

        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 request URI and set the Method parameter to Prefix and the Content parameter to /logout.

      3. The subsequent steps for creating a routing rule to match a URL that contains /logout are the same as those for creating a routing rule to match a URL that contains /productpage. 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.

        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 product information.

        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 Rule

        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 request URI, set Method to Prefix and Content to /api/v1/products.

      3. The subsequent steps for creating a routing rule to match a URL that contains /api/v1/products are the same as those for creating a routing rule to match a URL that contains /productpage. 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 Google Chrome, enter http://{IP address of the ASM gateway}/productpage.

      The following figure shows an example on the page that appears.访问服务

    2. In the upper-right corner of the Bookinfo page, click Sign in.

    3. On the Please sign in page, enter your account and password and click Sign in.

      The following figure shows the page of the Bookinfo service after logon.登录bookinfo

      You can also use a URL that contains /logout, /static, or /api/v1/products to access the Bookinfo service for verification.

    4. In the upper-right corner of Google Chrome, click the 更多 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.延迟

  4. (Optional) After the routing rules are created, view the YAML files that are automatically generated for the corresponding virtual services.

    1. On the details page of the ASM instance, choose Traffic Management Center > VirtualService in the left-side navigation pane.

    2. On the VirtualService page, find the virtual service that you want to manage and click YAML in the Actions column.

    3. In the Edit dialog box, view the YAML file of the virtual service. Confirm the settings and click OK.

Related operations

View service details

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. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

  3. On the Ingress Gateway page, click the name of the ASM gateway for which you want to view service details.

  4. In the left-side navigation pane of the Gateway overview page, click Upstream Service.

  5. On the Gateway upstream services page, find the service whose details you want to view and click service details in the Actions column.

  6. On the service details page, 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.

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

  3. On the Ingress Gateway page, click the name of the ASM gateway for which you want to disable a routing rule.

  4. In the left-side navigation pane of the Gateway overview page, click Route management.

  5. On the page that appears, find the desired routing rule and click offline in the Actions column.

  6. In the Submit message, click OK.

  7. 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 Please sign in page, 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.

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 Submit message, click OK.