Blue-green release is a zero downtime application update policy. During a blue-green release, the old and new service versions of an application coexist, and also share the Server Load Balancer instance. By adjusting the Server Load Balancer weights, you can switch traffic between different service versions. After the new version passes the verification, you can delete the old service version by confirming the release. If the new version does not pass the verification, the release is rolled back and the new version is deleted.
In the following example, assume that you want to perform a blue-green release for an Nginx static page application. The initial application template is as follows:
After the deployment, the page is as follows.
Each container needs to expose the host port. Therefore, when performing blue-green release with Server Load Balancer routing, make sure that the number of containers in a service is less than or equal to half the number of machines in the cluster. Otherwise, the port conflict occurs.
We recommend that you contract the number of containers to half the number of machines in the cluster before performing blue-green release with Server Load Balancer routing. Expand the number of containers to the original amount after the blue-green release is completed.
Log on to the Container Service console.
Click Applications under Swarm in the left-side navigation pane.
Select the cluster in which the application resides from the Cluster list.
Click Update at the right of the application.
Set the release mode and the configurations of the new service version.
- The new and old versions cannot share the same name.
- To make sure that the application does not experience downtime when switching versions, the weight of the new service version is set to 0 by default. On the route management page, you must adjust the weight to switch traffic to the new version.
The template sample is as follows:
Click OK to release the changed version.
The release process goes through two statuses:
- Blue-green release in progress: Indicates that the startup of the new service version is not completed.
Blue-green release awaiting confirmation: Indicates that the startup of the new service version is completed. Another release can be performed until this release is confirmed or rolled back.
Click the application name to go to the application details page. You can see that the new and old application versions coexist.
Click the Routes tab and then click Set service weight.
The Server Load Balancer weight of the old version is 100 and that of the new version is 0.
To realize zero downtime update, set the weight of the new version to 100. Now the new version and old version account for 50% of the weight respectively. Test if both versions have stable traffic.
Note: Adjusting the weights of the new version and old version at the same time might result in the failure of some requests. Therefore, adjust the weights in two steps and only adjust the weight of one version in each step. For example, adjust the weight of the new version from 0 to 100 first, and then adjust the weight of the old version from 100 to 0 after the traffic is stable.
Then, adjust the weight of the old version to 0 and that of the new version to 100.
You can open a new browser window to access the new version.
After the entire release process has been verified, click Confirm Release Completion on the Application List page. Select whether or not to automatically perform the smooth update in the displayed dialog box and click OK to confirm the release before you can release subsequent versions.
Now the service list of the application has been updated and the old service version has been taken offline and deleted.