Blue-Green Deployment CI/CD Pipeline: A Simple Guide

Alla YasheelaAlla Yasheela
6 min read

When working in DevOps, one of the main goals is to deploy code to production without causing any downtime or disruption to users. A common strategy used for this is called Blue-Green Deployment, which helps us roll out updates smoothly and ensures that users don't experience any service interruptions. In this guide, I'll explain how I built a Blue-Green Deployment CI/CD pipeline using tools like Terraform, Jenkins, Kubernetes, Docker, and SonarQube.

Let’s dive into how this process works and how the tools fit together to make it all happen.

What is Blue-Green Deployment?

In simple terms, Blue-Green Deployment is a method where two identical environments (called Blue and Green) are used to host your application. Here’s how it works:

  1. Blue Environment: This is the environment where your application is currently running.

  2. Green Environment: This is the new version of your application, ready to be deployed.

When a new version of your app is ready, it gets deployed to the Green environment. After testing and validating that everything is running smoothly, traffic is switched from the Blue environment to the Green environment. If something goes wrong during the deployment, we can quickly switch back to the Blue environment, avoiding any major issues.

This ensures zero-downtime deployments, meaning users don’t experience any interruptions or downtime during the update process.

Why Use Blue-Green Deployment?

Blue-Green Deployment comes with several key benefits:

  • Zero Downtime: Users don’t experience disruptions while updates are rolled out.

  • Risk Mitigation: Since both environments are identical, switching back to the old version (Blue) is quick and easy if something goes wrong.

  • Safe Rollbacks: If there are problems with the new version, switching back to the old version is seamless.

  • Quick Validation and Testing: The new environment (Green) can be thoroughly tested before traffic is directed to it.

  • Improved Flexibility: Blue-Green deployment allows for more flexible release strategies since the environment switch is simple.

Now, let’s go over the tools I used to create the pipeline.

Tools and Technologies Used

To build this Blue-Green Deployment pipeline, I used the following tools:

1. GitHub

GitHub was used for managing the source code of the application. It acts as a version control system where the code is stored and managed collaboratively.

2. Terraform

Terraform is an Infrastructure as Code (IaC) tool that helps in automating the setup and management of infrastructure. I used it to provision an AWS Elastic Kubernetes Service (EKS) cluster, which hosts the Kubernetes resources. Terraform makes it easy to define and create resources such as virtual machines, networks, and Kubernetes clusters through code.

3. Jenkins

Jenkins is a widely-used automation server. I used Jenkins to automate the Continuous Integration/Continuous Deployment (CI/CD) process. It automates tasks like code integration, testing, and deployment, allowing teams to focus more on development and less on manual processes.

4. SonarQube

SonarQube is a tool for performing static code analysis and checking the quality of the code. It helps detect bugs, vulnerabilities, and code smells early in the development process. By integrating SonarQube into the pipeline, I ensured that only high-quality code gets deployed to production.

5. Nexus

Nexus was used for artifact storage and management. Artifacts, such as Docker images, are stored in Nexus for use in the deployment process.

6. Docker & Docker Hub

Docker allows us to package the application into containers, making it easy to deploy and run consistently across different environments. Docker Hub is where these Docker images are stored, and from there, they are pulled during the deployment process.

7. kubectl & eksctl

kubectl is a command-line tool used to interact with Kubernetes clusters, while eksctl is a tool that simplifies the creation and management of AWS EKS clusters. Together, these tools are crucial in managing the Kubernetes infrastructure and ensuring that the application is deployed smoothly.

8. Kubernetes

Kubernetes is a powerful orchestration tool that manages containerized applications. In this project, Kubernetes handles the actual Blue-Green deployment strategy by managing the pods in the Blue and Green environments.

9. AWS EKS (Elastic Kubernetes Service)

AWS EKS is a managed Kubernetes service. It simplifies the process of running Kubernetes on AWS, making it easier to deploy, manage, and scale Kubernetes clusters.

Step-by-Step Process

Here’s how I implemented the pipeline:

1. Setting Up the EKS Cluster with Terraform

The first step was to use Terraform to provision the EKS cluster. Terraform scripts defined the infrastructure needed to create and manage the Kubernetes cluster on AWS.

2. Automating the CI/CD Pipeline with Jenkins

Once the infrastructure was in place, I set up Jenkins to automate the CI/CD pipeline. Jenkins was configured to:

  • Pull the latest code from GitHub

  • Build the Docker image of the application

  • Push the Docker image to Docker Hub

  • Run SonarQube checks to ensure the code quality is up to standards

  • Deploy the new version to the Green environment in Kubernetes using kubectl

3. Performing Blue-Green Deployment

After the new version was successfully deployed to the Green environment, it was tested to ensure everything was working correctly. Once validated, the traffic was switched from the Blue environment to the Green environment.

If any issues were found during testing, I could easily roll back by switching traffic back to the Blue environment.

4. Monitoring and Testing

After deploying to the Green environment, I monitored the application to make sure everything was functioning correctly. This process included checking logs, monitoring resource usage, and running test cases.

5. Switching Traffic

After validating the Green environment, the final step was to switch traffic from Blue to Green. This was done by updating the Kubernetes service to point to the new version running in the Green environment.

If any problems occurred, the process allowed for a quick rollback by simply directing traffic back to the Blue environment.

Challenges and Learnings

While working on this project, I faced a few challenges, particularly with ensuring the seamless switchover between Blue and Green environments. Issues like ensuring consistency in configuration, managing network traffic, and handling container orchestration required careful planning and testing. However, through trial and error, I was able to resolve these challenges and gain a deeper understanding of the Blue-Green Deployment strategy.

I completed this project in around 5 hours, learning a lot along the way.

Acknowledgements

I want to give a big shoutout to Aditya Jaiswal for his amazing work in the field of DevOps. His projects and insights have been invaluable to my learning journey.

Conclusion

Building a Blue-Green Deployment CI/CD pipeline is a great way to ensure zero-downtime deployments and reduce the risk of deploying updates to production. Using tools like Terraform, Jenkins, Kubernetes, Docker, and SonarQube, we can automate the entire process, making deployments faster, safer, and more efficient.

I’m excited to continue building more projects like this and exploring new ways to improve deployment strategies in the future!

0
Subscribe to my newsletter

Read articles from Alla Yasheela directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Alla Yasheela
Alla Yasheela

I'm Yasheela, an undergraduate with a deep interest in DevOps, and cloud technologies. Currently working on exciting projects on all things DevOps. I’m passionate about simplifying complex concepts and sharing practical insights. Through my Hashnode blog, I document my learning journey, from building scalable applications to mastering cloud services, with the goal of empowering others to grow their tech skills. Let's Learn Together !!