Enabling Blue-Green Release with Alibaba Cloud Container Service for Kubernetes

11.11 The Biggest Deals of the Year. 40% OFF on selected cloud servers with a free 100 GB data transfer! Click here to learn more.

When releasing an application, it is often necessary to first release a new version and then test its availability with a small amount of traffic. However, Kubernetes’s ingress resource does not implement traffic control and splitting. As a result, only one service is available in the directory with the same domain name. This is undesirable for a phased release. In this article, we will introduce Alibaba Cloud’s Container Service blue-green release function, which enables easy traffic splitting.


Since we need blue-green releases, there should already be an old service that is serving normally. Here we will take Nginx as an example. Assume that there is already an nginx deployment exposing ports through NodePort and an ingress is providing services. The template we will use is as follows:

We can see the created ingress address

When accessing via curl on the host, we can see the following results:

Performing Blue-Green Release

Creating New Deployment and Service

As you can see, the only change is that all old-nginxes become new-nginxes.

Modifying Ingress

There are primarily two additions:

  1. annotations is added, and the tag ingress.aliyun.weight/new-nginx: "50" indicates that the content after the slash (/) is the name of the new service, i.e., new service name. The following "50" represents the percentage (%), and 50 indicates that the new service occupies 50% of the traffic. The complete meaning of this tag is that 50% the traffic is switched into the pod of the new service.
  2. The second addition is to specify the corresponding new serviceName. This is in parallel with the above old service, that is to say, two different services exist in the same path and these services correspond to the new and old applications.


We can see that we have executed six requests and got three responses in return from the new service, while three were from the old service. This indicates that the weight setting has taken effect.

Switching Traffic to the New Service Completely

You can set the percentage of the new service to 100 and try again.

As we can see, all traffic has switched to the new service.

Finalizing the Blue-Green Release

We just need to delete the annotation of the weight setting, and then delete the corresponding serviceName below, thus restoring the original ingress, and changing the old service into a new service. Let's look at the effect again:

Now we can see that the new service is already online. This means that the lifecycle of the entire blue-green release is finished.

Read similar articles and learn more about Alibaba Cloud’s products and solutions at www.alibabacloud.com/blog.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.