Cloud Technology Community Question

How do I implement a Blue-Green deployment strategy in K8s?

Posted on 2024-01-22 • In Cloud Technology • By Elizabeth Taylor

I want to reduce the risk of downtime during our application releases by using a Blue-Green deployment. Currently, we just use the default RollingUpdate in Kubernetes, but it sometimes causes issues if the new version has a bug. How can I manage two identical environments and switch traffic between them using the Service or Ingress objects?

3 Answers 15,686 Views

All answers to this question 3 Answers

Helen Robinson Answered on 2024-01-24
Answered

The simplest way to do Blue-Green in vanilla Kubernetes is by using Labels and Selectors within your Service object. You maintain two separate Deployments: one labeled 'version: blue' and one 'version: green'. Your Service initially has a selector pointing to 'blue'. When you’re ready to switch, you update the Service's selector to 'green' using kubectl patch. If things go wrong, you simply patch it back to 'blue'. For more advanced traffic splitting, you might want to look into an Ingress Controller like NGINX or a Service Mesh.

Steven Hall Answered on 2024-01-25
Answered

Have you considered using a tool like Argo CD or Flux for this? Manual patching works, but it’s prone to human error. GitOps tools can automate the entire transition and even handle the health checks for you.

Elizabeth Taylor Commented on 2024-01-26
Commented

Steven, I actually looked into Argo Rollouts after reading your comment. It seems much more robust than my manual patching idea! It supports "AnalysisTemplates" which can automatically roll back the traffic to the 'Blue' environment if Prometheus metrics show an increase in 5xx errors during the 'Green' phase. This is exactly the kind of automated safety net our DevOps team has been looking for.

Nancy Young Answered on 2024-01-27
Answered

Blue-Green is great, but remember it requires double the resources since you run two versions of the app at once. Make sure your cluster has enough headroom!

Helen Robinson Commented on 2024-01-28
Commented

Good point, Nancy. We always check our node capacity before starting a Blue-Green shift to avoid scheduling failures during the peak traffic hours.

Write a Comment

Your email address will not be published. Required fields are marked (*)

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.