How to implement Blue-Green Deployment with HPA?

3/22/2019

I have two colored tracks where I deployed two different versions of my webapp (nginx+php-fpm), These tracks are available by services, called live and next.

The classic way would be deploying new version of webapp to next, after checking, release it to live by switching their services.

So far so good.

Considering autoscaling with HPA: Before doing a release I have to prescale next to the amount of live pods to prevent too heavy loads after switch.

Problem here is the nature of HPAs cpu load measuring. In worst case the autoscaler will downscale the prescaled track immediately, cause of calculating cpu load coming from next.

Another problem i found is using keepalive connections, which makes releasing new pods to live very hard without killing old pods.

How to solve the problem?

-- Mamuz
kubernetes

1 Answer

4/19/2019

We have a few deployment strategies (there are more but I will point the most common).

1) Rolling Update - We need only one deployment. It will add pods with new content to current deployment and terminating old version pods in the same time. For a while deployment will contain mix of old and new version.

2) Blue-Green Deployment - It is the safest strategy and it is recommended for production workloads. We need to have two deployments coexisting i.e v1 and v2. Im most cases old deployment is draining (close all connections/sessions to old deployment) and redirected all new sessions/connections to new deployment. Usualy both deployments are keept for a while as Production and Stage.

3) Canary Deployment - The hardest one. Here you also need at least two deployments running at the same time. Some users will be connected to old application, others will be redirected to new one. It can be achieved via load balancig/proxy layer configuration. In this case HPA is not allowed because we are using two deployments at the same time and each deployment will have own independent autoscaler.

Like @Mamuz pointed in comment Blue-Green Strategy without switch on service level sounds much better in this case than rolling-update.

Another option which might be useful in this scenario is Blue-Green Deployment with ISTIO using Traffic Shifting. In this option you could divide traffic as request i.e. from 100-0, 80-20, 60-40, 20-80 to 0-100%

Using ISTIO and HPA step by step is described in this article.
You can read about Traffic Management here.
Example of Istio and K8s here.

-- PjoterS
Source: StackOverflow