Practical overview of the Blue Green Deployment Strategy
Close Icon
×
Knowledge Center

Practical Overview of ‘Blue Green Deployment Strategy’ for Continuous integration and delivery with Pivotal Cloud Foundry (PCF)

Practical Overview of ‘Blue Green Deployment Strategy’ for Continuous integration and delivery with Pivotal Cloud Foundry (PCF)

There are multiple application deployment strategies that help in minimizing the impact of frequent deployments on the availability of information and on business. Each strategy has its pros and cons.  Selecting the right one is determined by the needs and constraints of IT & business.  These strategies range from Big Bang Deployment, Phased/Ramped Deployment to Blue-Green Deployment, Canary and A/B testing deployment.

The Blue-Green Deployment Strategy is a popular technique. It has two identical production environments, usually named Blue and Green. The use of identical environments is to reduce risk and downtime.  Blue-Green Deployment Strategy fully supports the continuous delivery model. Under this strategy, any work that may be ongoing on apps does not (ever) hamper the availability of the apps.  At any time, one of the environments, such as blue, is live and current. During an update, the non-live version of the environments is updated and readied (green) and tested. Once final, the green production environment is made live.

The blue-green strategy is often used to deploy microservices applications on cloud or in-house infrastructure. Pivotal Cloud Foundry (PCF), a cloud-native platform for deploying and operating modern applications, enables the in-house infrastructure to serve as a cloud and infrastructure as a service:

  • PCF changes the routes from the load balancer, helping to switch between the blue and the green environments.
  • PCF provides granular control on domains and routes where the application is deployed, streamlining the blue-green deployment strategy and implementing it as part of a continuous delivery DevSecOps pipeline.
  • Routes represent the unique address of each application hosted under a cloud foundry domain. If an application named “notes“ is hosted in PCF as https://notes.cfapps.io/, for example, io represents the domain name in which notes application is registered and accessible through the https://notes.cfapps.io/ route.

Let’s consider that we have a microservice named “notes-service” for which we need to implement the blue-green deployment.

  1. ‘notes-service-blue’ represents the current ‘Live’ version of the microservice, running on production.
  2. ‘notes-service-green’ represents the new version of the microservice that needs to be deployed on production.

Implementation of a blue-green deployment strategy with PCF requires the following steps:

  1. Deploy the application version A in the blue environment with route blue.

‘Live route’ handles current live traffic and routes to the application version deployed in the blue environment

 

  1. Deploy the application new version B on the green environment with route green.

‘Temporary route’ handles the new application version deployed in the green environment.  Once it’s running, internal testing is completed to validate its functionality before routing the live traffic to this version.

 

After steps 1 and 2 in the CF dashboard, navigate to the routes section, and it will provide the following routes:

  1. Map the ‘green’ environment to the current live traffic route.

This will start routing the live traffic on both blue and green environments rendering both application versions active.

  1. Unmap the blue environment from the current live traffic route

Once the new version is stable and working, unmap the blue environment from the current live route to keep live requests now being served through the new application version (green).

 

  1. Remove the temporary route

Up till this step, both live and temporary routes can be used to access the new application version. Once the new version is determined to be stable, remove the temporary route so that the new version is accessible only through the live route. The blue is now the temp environment and kept available as part of the rollback strategy.

 

Plugging the ‘blue-green deployment strategy’ in the DevOps pipeline DevOps is crucial to the software development life cycle, the blue-green deployment strategy can be plugged into a DevSecOps pipeline to automate the preparation and the availability of the green environment with a new version, boosting the testing in the green environment and then rolling out the new version to market quickly.  Building the deployment strategy as part of the DevSecOps pipeline also helps in ensuring the application quality and validating the application on several security aspects before turning it for production live traffic and hence is gaining momentum in making it an integral part of DevSecOps pipeline.

For instance, negative testing on applications, integrated with the DevSecOps pipeline, will validate if the application behaves securely; at the same time, it receives a corrupted or vulnerable data request.  These tests would be useful to streamline the vulnerabilities management. When a vulnerability is identified in the current live (blue) environment, a patch is deployed on the green instance to resolve the vulnerability and then taken live, ensuring there is no downtime for the users.

Here is an example of blue-green deployment strategy using the Jenkins pipeline in the “notes-service” application mentioned above:

  1. Blue pipeline: build and deploy notes-service-blue on the blue environment.
  2. Green pipeline - build and deploy notes-service-green on the green environment.
  3. Blue-green switch pipeline — switch between blue and green environments for rolling out the new version (notes-service-green) or to roll back to a previous version (notes-service-blue).

Follow the below mentioned sample Jenkins pipeline script to set up a blue and green pipeline

Integration test cases need to be set up to automate the deployment completely with integration testing and traffic routes switchover to combine the green and blue-green switch pipeline together.

 

Follow the below sample Jenkins pipeline script for blue-green switch pipeline to setup:

Deploy the green (new version) to the staging environment  

 

Execute Integration Test cases in the staging environment

Switch routes to route the live production traffic to the green (new version) application code

 

The blue-green deployment strategy is immensely beneficial, and it can play an integral role in bringing agility in application deliveries and supporting business continuity. It helps automate the deployment process with zero downtime along with the automated integration testing of a new version in a production ready environment. The one drawback, at least for some businesses, is that it increases the overall cost of infrastructure to host two identical application environments. But, the business benefits from shorter deployment cycles lead to reduced time to market, customers get product value in less time, and customer feedback reaches the product team faster which meant it can fix problems faster.

Need help in implementing your blue-green deployment strategy? Then reach out to our experts here.

 

About the Author

Shashank Jain

A passionate technologist, Shashank has a master’s in IT Cybersecurity and is currently working as a solution architect with Infogain’s key client, a fortune 50 courier delivery services company. A microservices expert, Shashank architects, and implements micro-services based scalable distributed APIs, DevSecOps software delivery pipelines.