Using traffic routing with an ASM gateway

更新时间:
复制 MD 格式

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

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

  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 target gateway. In the navigation pane on the left of the Gateway Overview page, click Domain/Certificate.

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

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

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

  1. Manage service versions.

    This example groups the instances of the reviews service into three versions: v1, v2, and v3.

    1. On the Upstream Service page, find the reviews service and click versions in the Operator column.

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

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

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

  2. Create a traffic policy.

    1. On the Upstream Service page, find the reviews service and click traffic policy in the Operator column.

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

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

    Note

    Alternatively, in the navigation pane on the left of the mesh details page, choose Traffic Management Center > DestinationRule. 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.

    YAML

    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. Create routing rules.

    1. Create a routing rule for /productpage.

      1. In the navigation pane on the left of the Gateway Overview page, click Route management, and then click Create.

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

        Note

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

        Note

        You can also click Add Header Matching Rule to set header matching.

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

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

    2. Create a routing rule for /static.

      1. On the Route management page, click Create.

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

      3. The steps for creating the /static route are the same as those for the /productpage route. For details, see Create the productpage route.

    3. Create a routing rule for /login.

      1. On the Route management page, click Create.

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

      3. The subsequent steps to create the /login route are the same as those for the /productpage route. For the detailed steps, see Create the productpage route.

    4. Create a routing rule for /logout.

      1. On the Route management page, click Create.

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

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

    5. Create a routing rule for /api/v1/products.

      1. On the Route management page, click Create.

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

      3. The subsequent steps to create the /api/v1/products route are the same as those for creating the /productpage route. For details, see Create the productpage route.

  2. Verify the routing rules.

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

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

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

    4. Open your browser's developer tools and switch to the network tab.

    5. Refresh the page.

      A delay of about 4 seconds is observed. In the Network panel of your browser's developer tools, the productpage request 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.

  3. (Optional) View the YAML file of the virtual service that is generated after the routing rules are created.

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

    2. On the Virtual Service page, find the target virtual service and click View YAML in the Operator column.

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

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

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

  1. On the Ingress Gateway page, click the name of the target gateway.

  2. In the navigation pane on the left of the Gateway Overview page, click Route management.

  3. On the Route management page, find the target routing rule and click offline in the Operator column.

  4. In the Confirm dialog box, click OK.

  5. Verify that the routing rule is offline.

    1. In the address bar of your browser, enter http://{IP address of the ingress gateway}/productpage.

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

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

      Note

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