Author- Anubhav Bisht (Cloud Engineer)
Overview
Continuous integration (CI) and continuous deployment (CD) form a pipeline by which you can build, release, and deploy your code. Jenkins provides a complete, fully featured set of CI/CD automation tools for deployment. It is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. Modern applications are increasingly built using containers, which are microservices packaged with their dependencies and configurations. Kubernetes is open-source software for deploying and managing those containers at scale.
A blue/green deployment is a change management strategy for releasing software code. Blue/green deployments, which may also be referred to as A/B deployments require two identical hardware environments that are configured exactly the same way. While one environment is active and serving end users, the other environment remains idle.
This post describes how to setup a Blue-Green Deployment CI/CD pipeline using Jenkins for deploying a containerized custom Application working with Azure Kubernetes Service.
Prerequisites:
- An Azure account with following services:
- A Jenkins account for performing CI/CD with following plugins installed:
- Azure Credentials
- Docker Pipeline
- Jackson 2 API (2.10.3)
- Snakeyaml API (1.26.2.)
Code Structure:
You can find the Sample Code here and clone it to your local.
Building Deployment Project :
- Add the Service Principal details of your Azure instance in Jenkins Credentials
- Add the credentials of Azure Container Registry in Jenkins Credentials
- Update the details in the Jenkinsfile at todo-app-java-on-azure/deploy/aks/Jenkinsfile location
- Connect to your cluster using following command
az aks get-credentials –resource-group <resource-group name> –name <cluster-name>
- Deploy the .yml files at todo-app-java-on-azure/deploy/aks location to the cluster as
kubectl apply -f service-green.yml
kubectl apply -f test-endpoint-blue.yml
kubectl apply -f test-endpoint-green.yml
- In the Jenkins dashboard select New Item and select Pipeline as Project and select OK
- From the configuration options select the following and add details accordingly and SAVE
- Select the project and click Build Now and let the pipeline build
- Once the pipeline is finished, you can check the image in the Azure container Registry
- Now go to the Kubernetes cluster and in the left panel select Services and Ingress to see the blue/green deployment service External IP
- If you browse both the IPs, then, only IP for todoapp-test-blue will work but not for todoapp-test-green since the application is deployed to only BLUE environment
- Now, go to the Jenkinsfile and change the environment variable currentEnvironment to green
- Now build the pipeline again and refresh the webpage with the IP of todoapp-test-green and you will be able to see application deployed to the GREEN environment as well
Both, Blue and Green environment now have same application deployed. One(let’s say Blue) will be in the production phase and other(Green) will remain idle. Whenever there is any change to be made then the idle(Green) one is moved to production phase and changes are made to the other(Blue) environment so as to keep the application available for public.