edit-icon download-icon

Blue-green release policy with Server Load Balancer routing

Last Updated: Feb 05, 2018

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.

Scenarios

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:

  1. nginx-v1:
  2. image: 'registry.aliyuncs.com/ringtail/nginx:1.0'
  3. ports:
  4. - 80:80/tcp
  5. labels:
  6. aliyun.lb.port_80: tcp://proxy_test:80
  7. restart: always

After the deployment, the page is as follows.

Instructions

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.

Procedure

  1. Log on to the Container Service console.

  2. Click Applications under Swarm in the left-side navigation pane.

  3. Select the cluster in which the application resides from the Cluster list.

  4. Click Update at the right of the application.

    1

  5. Set the release mode and the configurations of the new service version.

    Note:

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

    1

    The template sample is as follows:

    1. nginx-v2:
    2. image: 'registry.aliyuncs.com/ringtail/nginx:2.0'
    3. ports:
    4. - 80:80/tcp
    5. labels:
    6. aliyun.lb.port_80: tcp://proxy_test:80
    7. restart: always
  6. 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.

      1

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

    1

    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.

    1

  8. You can open a new browser window to access the new version.

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

    1

    Now the service list of the application has been updated and the old service version has been taken offline and deleted.

Thank you! We've received your feedback.