All Products
Search
Document Center

Microservices Engine:Configure tag-based routing

Last Updated:Oct 16, 2024

You can use the tag-based routing feature to tag traffic or machines. This enables traffic that meets specific characteristics to be routed to specific nodes. The tag-based routing feature is suitable for scenarios such as blue-green deployments and canary releases.

Prerequisites

Limits

Note

This section describes the limits that apply to applications for which Microservices Governance is enabled.

For more information about the Java versions and frameworks supported by tab-based routing, see Java frameworks supported by Microservices Governance.

Scenarios

Multi-version development and testing

If multiple versions are developed at the same time, you must prepare a development environment for each version. The costs of development environments are high. To reduce costs, you can use tag-based routing to implement end-to-end traffic adjustment. End-to-end traffic adjustment is implemented based on the tag-based routing feature. End-to-end traffic adjustment allows you to route specific traffic to a specific development environment. For example, in Development Environment 1, create Tag 1 for Application B (V1.1) and Application D (V1.1), and configure a tag-based routing rule. This way, when Application A calls Application B, the system checks whether the traffic meets the conditions of the tag-based routing rule. If yes, the traffic is routed to Application B (V1.1) in Development Environment 1. If no, the traffic is routed to Application B (V1) in the baseline environment. When Application C calls Application D, the traffic is routed to Application D (V1) or Application D (V1.1) based on the tag-based routing rule.

Traffic adjustment for a multi-version application

If multiple versions of an application run online at the same time and are deployed in different environments, such as the common environment and special environment, you can use the tag-based routing feature to isolate the traffic that is destined for different versions in different environments. For example, you can route the traffic of flash sales orders or the traffic of orders from different channels to the special environment, and route common traffic to the common environment. This way, the traffic that is destined for the special environment is not routed to the common environment even if exceptions occur in the special environment, and the common environment is not affected.

A/B testing

Multiple versions of an application run online at the same time. To perform A/B testing on the different versions of the application, you can use end-to-end traffic adjustment to route the traffic that is initiated from Region A to Application V1, and route the traffic that is initiated from Region B to Application V1.1. Then, you can verify the different versions. This helps reduce risks when you release new products or features and facilitates product innovation.

Enable Microservices Governance for the application in the ACK cluster and add tags to the application instances

In this section, tag1 and tag2 are added to the instances of an application named spring-cloud-a and the instances are divided into two groups based on their tags. If a request matches a rule, the request is routed to the instance with the specific tag. If no rule is matched, the request is routed to an instance based on the configured percentage for traffic routing.

  1. Log on to the ACK console.

  2. In the left-side navigation pane, click Clusters. Then, click the name of the cluster that you want to manage.

  3. In the left-side navigation pane, choose Workloads > Deployments.

  4. In the upper-right corner of the Deployments page, click Create from Image.

  5. In the Create wizard, create two deployments named spring-cloud-a-tag1 and spring-cloud-a-tag2. For more information, see Create a stateless application by using a Deployment.

    Parameter

    Description

    Replicas

    Set this parameter to 1.

    Type

    Set this parameter to Deployment.

    Image Name

    Select the image that you created. Click Select images next to the Image Name field. In the Select images and image tags dialog box, select China (Hangzhou) from the region drop-down list and select registry.cn-hangzhou.aliyuncs.com/mse-governance-demo/spring-cloud-a:3.0.1.

  6. Enable Microservices Governance for spring-cloud-a-tag1 and spring-cloud-a-tag2 and add tags to spring-cloud-a-tag1 and spring-cloud-a-tag2.

    1. Go to the Deployments page. Select the namespace to which spring-cloud-a-tag1 belongs from the Namespace drop-down list. Find spring-cloud-a-tag1 and choose More > View in YAML in the Actions column. Perform the same operations for spring-cloud-a-tag2.

    2. In the Edit YAML dialog box, add the following labels to spec > template > metadata for spring-cloud-a-tag1. Perform the same operation for spring-cloud-a-tag2. After you perform this step, Microservices Governance is enabled for spring-cloud-a-tag1 and spring-cloud-a-tag2.

      labels:
        msePilotAutoEnable: "on"
        msePilotCreateAppName: <your-app-name>
        alicloud.service.tag: <tag>
      Note
      • Replace <your-app-name> with the application name that you use in Microservices Governance. In this example, the application name is spring-cloud-a.

      • Replace <tag> with tag1 or tag2.

    3. Click Update.

Create tag-based routing rules for the application in the MSE console

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. On the Application list page, select the desired namespace, search for the application spring-cloud-a that you created in the ACK cluster, and click the application.

  4. In the left-side navigation pane, click Traffic management. On the page that appears, click the Label routing tab to view the tag-based routing configurations.

  5. On the Label Routing tab, configure Flow ratio that are specific to tags, and click Save.

    image

  6. Find the tag to which you want to add a traffic rule and click Add in the Traffic rules column. In the Create Tag-based Routing panel, configure the parameters and click OK.

    image

    Note

    If the tag-based routing feature is used, routing conditions in a traffic rule are preferentially used. If the traffic rule is met, the traffic is routed to the pod that corresponds to the tag in the traffic rule. Otherwise, the traffic is routed to the pod that corresponds to the tag based on the specified traffic percentage.

    Parameter

    Description

    Routing Rule Name

    The name of the tag-based routing rule. Example: test-springcloud.

    Application

    The name of the application. Example: spring-cloud-a.

    Tag

    The tag that you added to the application in the ACK cluster. Example: tag2.

    Application Instance

    The IP address and port number of the application instance with this tag.

    Traffic Rules

    Framework Type

    Select Spring Cloud or Dubbo based on the framework of the application.

    • Spring Cloud: You can select a URL path, such as /getIp, from the drop-down list. You can also specify a custom URL path.

    • Dubbo: You can select a specific service and interface.

    Condition Mode

    Select Meet All Conditions or Meet One of Conditions based on your business requirements.

    Conditions

    • If Framework Type is set to Spring Cloud, you can select Parameter, Cookie, Header, or Body Content from the Parameter Type drop-down list. Sample configurations: name=xiaoming if Parameter Type is set to Parameter and hello = "world" or hello = "world2" if Parameter Type is set to Cookie.

    • If Framework Type is set to Dubbo, you must configure the Expression for Getting Parameter Values parameter.

Verify the result

Verify the result based on your business requirements.

  • Create a rule to route all traffic to spring-cloud-a-tag1.

    image

  • Create a rule to route traffic that meets specific conditions to specific applications.

    image

References

For more information about how to implement end-to-end canary releases, see End-to-end canary release.