To safely release new versions of a microservice application and gradually validate new features, use Argo CD to perform an end-to-end canary release. This method provides fine-grained traffic scheduling and version management, ensuring a seamless switch between versions. This minimizes the impact on online services and improves system stability.
Prerequisites
-
An ASM instance of Enterprise Edition or Ultimate Edition is created, and the instance version is 1.20.6.27 or later. For more information, see Create an ASM instance and Upgrade an ASM instance.
-
Argo CD is installed and an ASM gateway is created. For more information, see Steps 1 to 3 in Integrate Argo CD with ASM to implement GitOps.
-
You have connected to the Kubernetes cluster by using kubectl. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Background information
Argo CD uses the GitOps approach to deploy and release application services. Developers commit YAML manifests for application resources such as Deployments and Services, and traffic management rules such as VirtualServices, Gateways, and DestinationRules to a Git repository. Argo CD monitors the status of these resources in the cluster and compares them with the desired state defined in the Git repository. With the Git repository as the source of truth, Argo CD can automatically or manually synchronize the resources when changes are detected.
Service Mesh ASM supports using traffic lanes to isolate specific versions (or other characteristics) of an application into an independent runtime environment to facilitate end-to-end canary releases for application services. Starting from version 1.20.6.27, ASM supports defining traffic lanes by using two custom resources written in YAML: ASMSwimLaneGroup and ASMSwimLane. You can use Argo CD to manage these custom resources to implement end-to-end canary releases. For more information, see Traffic lane overview.
Step 1: Deploy application and traffic lanes
-
Create an end-to-end canary release sample for the mock application.
-
In the Argo CD UI, click NEW APP and configure the following parameters.
Parameter
Description
Application Name
The name of the application. In this example, enter
mock.SYNC POLICY
The application's sync policy. In this example, select
Automatically. This setting automatically synchronizes the latest resource definitions from the Git repository. SelectPRUNE RESOURCESto ensure that resources are deleted from the cluster if their definitions are removed from the Git repository.Repository URL
The URL of the source Git repository. In this example, enter the sample repository URL
https://github.com/AliyunContainerService/asm-labs.git. If you want to modify the sample, fork this repository and enter the URL of your forked repository.Revision
The Git tag or branch name to synchronize from. In this example, enter the sample repository branch
argocd-asm.Path
The path in the repository that contains the resource manifests. In this example, enter the path of the resources used in the sample:
argo-cd/swimlane.Cluster URL
The API server address of the destination cluster. In this example, enter the API server address of the Kubernetes cluster where Argo CD is deployed:
https://kubernetes.default.svc.
-
-
After you complete the configuration, click CREATE at the top of the page.
On the Applications page in Argo CD, you can view the status of the
mockapplication that you just created.The application status should be Healthy and the sync status should be Synced, which indicates that the application is successfully deployed and synchronized.
-
Click the
mockapplication to view the sync status of its resources.The resource view shows that the application status is Healthy and the sync status is Synced, and all resources are synchronized without errors.
In addition to the Deployment and Service resources that define the application, the Git repository also contains traffic management resources such as VirtualService and Gateway, and ASM traffic lane resources such as ASMSwimLaneGroup and ASMSwimLane.
Step 2: Verify the end-to-end canary release
In this example, the ASMSwimLaneGroup and ASMSwimLane resources isolate the v1 and v2 environments for the application services. A VirtualService resource directs the ASM gateway to forward traffic to the two versions at a 1:1 ratio. You can repeatedly access the ASM gateway to verify the end-to-end canary release.
-
Obtain the public IP address of the gateway from the ASM console. For more information, see Obtain the IP address of an ASM gateway.
-
Run the following command to set an environment variable.
Replace
xxx.xxx.xxx.xxxwith the IP address from the previous step.export ASM_GATEWAY_IP=xxx.xxx.xxx.xxx -
Run the following command to repeatedly access the ASM gateway.
for i in {1..100}; do curl http://${ASM_GATEWAY_IP}/mock; echo ''; sleep 1; done;Expected output:
-> mocka(version: v2, ip: 10.0.239.73)-> mockb(version: v2, ip: 10.0.239.136)-> mockc(version: v2, ip: 10.0.239.139) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v2, ip: 10.0.239.73)-> mockb(version: v2, ip: 10.0.239.136)-> mockc(version: v2, ip: 10.0.239.139) -> mocka(version: v2, ip: 10.0.239.73)-> mockb(version: v2, ip: 10.0.239.136)-> mockc(version: v2, ip: 10.0.239.139) -> mocka(version: v2, ip: 10.0.239.73)-> mockb(version: v2, ip: 10.0.239.136)-> mockc(version: v2, ip: 10.0.239.139) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) -> mocka(version: v2, ip: 10.0.239.73)-> mockb(version: v2, ip: 10.0.239.136)-> mockc(version: v2, ip: 10.0.239.139) -> mocka(version: v1, ip: 10.0.239.75)-> mockb(version: v1, ip: 10.0.239.138)-> mockc(version: v1, ip: 10.0.239.137) ...The output indicates that the sample application consists of three services:
mocka,mockb, andmockc. The service call chain ismocka→mockb→mockc, and each service has a v1 and a v2 version. Requests are sent to the v1 and v2 versions of the application at an approximate 1:1 ratio. The isolated service call chain for each version demonstrates a successful end-to-end canary release.
Related operations
Release a new service version
The sample Git repository used in this example has the following file structure:
|
File |
Description |
|
mock-v1.yaml mock-v2.yaml |
Deployment definitions for the v1 and v2 versions of the |
|
swimlanegroup.yaml |
The lane group definition. A lane group is associated with one or more traffic lanes and defines shared information for them. This specifies the |
|
swimlanes.yaml |
The traffic lane definitions. This file defines two |
|
mock-route.yaml |
Defines the Gateway and VirtualService resources that apply to the ASM ingress gateway. These traffic management resources control how the ASM gateway routes requests to services in each traffic lane. |
To release a new application service version, fork the argocd-asm branch of the https://github.com/AliyunContainerService/asm-labs.git sample repository. Modify the YAML resources in the argo-cd/swimlane path and commit the changes. After you push the commit, Argo CD automatically synchronizes the changes. Ensure that the Repository URL in Step 1 is set to your forked repository's URL.
For example, to release a new v3 version for the mocka, mockb, and mockc services, modify the YAML resources in your Git repository as follows:
-
Add the
argo-cd/swimlane/mock-v3.yamlfile.This YAML file defines the Deployments for the v3 versions of the
mocka,mockb, andmockcservices. -
Modify the
argo-cd/swimlane/swimlanes.yamlfile with the following content.A new traffic lane (ASMSwimLane) named
v3is added. This resource is associated with themocklane group (ASMSwimLaneGroup) and specifies that Pods with theversion:v3label belong to the v3 service version. -
Modify the
argo-cd/swimlane/mock-route.yamlfile with the following content.The VirtualService named
mockis modified by adding the v3 version of themockaservice to the route destinations. Thesubsetfield maps to the name of the traffic lane (ASMSwimLane). Theweightfield in the VirtualService is adjusted to split the traffic between the v1, v2, and v3 versions in a 6:3:1 ratio.