Tag-based routing works by tagging traffic and nodes, then adding routing capabilities to direct traffic with specific characteristics to nodes with corresponding tags. This method provides a foundation for advanced deployment strategies like blue-green deployment and canary release.
Prerequisites
Limitations
This feature is available in the MSE Governance Center and requires your applications to be connected to it.
For a list of Java versions and frameworks that support tag-based routing, see Java frameworks supported by Microservices Governance.
Use cases
Multi-version development and testing
Developing multiple application versions in parallel requires a separate development environment for each version, leading to high resource costs. A traffic isolation strategy can significantly reduce these costs. By using end-to-end traffic isolation based on tag-based routing, you can direct specific traffic to a designated development environment. For example, in Development Environment 1, you can apply the Tag1 tag to version V1.1 of Application B and Application D and configure a corresponding routing rule. When Application A calls Application B, the system checks if the traffic matches the routing rule. If it does, the traffic is routed to the V1.1 instance of Application B in Development Environment 1. Otherwise, it is routed to the V1 instance in the baseline environment. Similarly, when Application C calls Application D, traffic is routed to either the V1 or V1.1 instance of Application D based on the traffic characteristics.

Multi-version traffic isolation
If multiple versions of an application run online in different environments, such as a regular environment and a special-purpose one, you can use tag-based routing to isolate traffic between them. For example, you can route traffic from flash sales or specific channels to the special-purpose environment, while directing normal traffic to the regular environment. This ensures that even if the special-purpose environment fails, traffic intended for it will not be routed to the regular environment, preventing any impact on the regular environment.

A/B testing
To perform A/B testing on multiple application versions, you can use tag-based routing for end-to-end traffic control. For example, you can route customer traffic from Region A to the V1 version and traffic from Region B to the V1.1 version. By validating different versions, you can reduce the risks associated with launching new products or features.

Enable Microservices Governance and set tags
This topic uses an application named spring-cloud-a as an example. You will apply tag1 and tag2 to create two groups of application instances. If a request matches the conditions you configure, it is routed to an instance with the specified tag. If no rules are matched, traffic is distributed to instances based on the configured traffic distribution percentages.
-
Log on to the Container Service for Kubernetes (ACK) console.
-
In the navigation pane on the left, choose Clusters, and then click the name of the target cluster.
-
In the navigation pane on the left, choose .
-
Click Create from Image to create two
Deploymentworkloads namedspring-cloud-a-tag1andspring-cloud-a-tag2. For more information, see Create a stateless workload Deployment.Parameter
Description
Replicas
Set the value to 1.
Type
Select Deployment.
Image name
Select your built image or use the pre-built image
registry.cn-hangzhou.aliyuncs.com/mse-governance-demo/spring-cloud-a:3.0.1. -
Follow these steps to connect
spring-cloud-a-tag1andspring-cloud-a-tag2to Microservices Governance and set their tags.-
Return to the Deployments page. Select a Namespaces and find the applications you created (spring-cloud-a-tag1 and spring-cloud-a-tag2). In the Actions column, choose More > View in YAML.
-
In the Edit YAML dialog box, add the following labels under for both
spring-cloud-a-tag1andspring-cloud-a-tag2to connect them to Microservices Governance.labels: msePilotAutoEnable: "on" msePilotCreateAppName: <your-app-name> alicloud.service.tag: <tag>Note-
Replace
<your-app-name>with your application's name in Microservices Governance. In this example, the name isspring-cloud-a. -
Replace
<tag>withtag1ortag2.
-
-
Click Update.
-
Create a tag-based routing rule
-
Log on to the MSE Governance Center console, and select a region in the top navigation bar.
-
In the left-side navigation pane, choose Microservices Governance > Application Governance.
-
On the Application list page, select the desired microservice namespace, search for the application spring-cloud-a that you created in ACK, and then click its name.
-
In the left navigation pane, click Traffic Management, and then click the Tag-based Routing tab to view the current routing configuration.
-
In the Tag-based Routing list, click Traffic Distribution, set the traffic percentage for each tag, and then click Save.
For example, set the traffic percentage for tag1 to
100%, and the percentages for tag2 and untagged instances to0%. -
Under Traffic Rules, click Add. In the Create Tag-based Routing panel, configure the parameters and click OK to create the routing rule.
NoteTag-based routing prioritizes conditions defined in a traffic rule. If a request matches a traffic rule, it is routed to a pod with the corresponding tag. Otherwise, the request is routed to a pod based on the specified traffic distribution percentages.
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 set for the application in ACK. Example:
tag2.Application instance
The IP address and port of the
spring-cloud-aapplication instance that has this tag.Traffic rules
Framework type
Select your application's framework: Spring Cloud or Dubbo.
-
For Spring Cloud, you can only set the URL path, such as
/getIp. -
For Dubbo, you can select a service and an interface.
Condition mode
Select a condition mode based on your requirements: Meet all of the following conditions or Meet any of the conditions.
Condition list
-
If Framework Type is Spring Cloud, you can set conditions based on Parameter, Cookie, Header, or Body Content. For example, a Parameter condition could be
name=xiaoming, and a Cookie condition could behello = "world" or "world2". -
If Framework Type is Dubbo, you must specify an expression to retrieve parameter values.
-
Verification
Verify the results based on your business requirements.
-
By default, 100% of the traffic is routed to the node with the
tag1tag.Atag1[192.168.0.122][config=base] -> B[192.168.0.147] -> C[192.168.0.115] -
Traffic that matches the rule is routed to the node with the corresponding tag.
Atag2[192.168.0.156][config=base] -> B[192.168.0.120] -> C[192.168.0.115]
Related documentation
To learn how to implement an end-to-end canary release, see End-to-end canary release.