Blue – Green Deployment
If you are around DevOps or people who are working with deployments in your industry, then you must have heard of the name blue green deployment. Most of the organizations in the world use this technique to get the minimum down time for their respective products. This deployment is old but still one of the finest to use. So, explore this article and know what actually is blue green deployment.
WHAT EXACTLY IS THE BLUE-GREEN DEPLOYMENT
A blue-green deployment is a change management strategy for releasing software code. Blue/green deployment is also referred as A/B deployments which 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.
Blue-green deployments are often used for consumer-facing applications and applications with a serious uptime requirement. New code is released to the inactive environment, where it is thoroughly tested. Once the code has been assessed, the team makes the idle environment active, typically by adjusting a router configuration to redirect application program traffic. The process gets reversed when the next software iteration is ready for release.
THE STEP-BY-STEP PROCESS OF BLUE-GREEN DEPLOYMENT
To demonstrate this concept, first the user needs to set up two server environments. Each will have a web server installed. In this example, the web server represents an entire application stack which could include a load balancer, multiple web servers, and distributed or replicated databases in the backend. In this example the user has used a web server because it represents the smallest environment that can demonstrate the release pattern.
CREATE A LOCAL APPLICATION
We will start by creating “application”. This is an index page that the web servers can display. It allows the user to demonstrate different “versions” of the app without the overhead of actual development. On local system, install git using the platform’s preferred method. If the user’s local machine is running Ubuntu, then the user can install by typing,
local$ sudo apt-get update
local$ sudo apt-get install git
The user need to set a few configuration settings in order to commit to a git repository. The user can give name and email address by typing:
local$ git config –global user.name “Your Name”
local$ git config –global user.email firstname.lastname@example.org
With the configuration set, the user can create a directory for their new application and move into it:
local$ mkdir ~/sample_app
local$ cd ~/sample_app
Initialize a git repository in our application directory by typing:
local$ git init
Now, create the index.html file that represents the application:
local$ nano index.html
Save and close the file when it is finished.
To finish up, the user can add the index.html file to the git staging area and then commit by typing:
local$ git add .
local$ git commit -m “initializing repository with version 1″
CONFIGURE THE BLUE AND GREEN WEB SERVERS
Next, work on setting up green and blue environments with functional web servers. Log into your servers with your sudo user to get started.
HOW DOES BLUE GREEN DEPLOYMENT WORK WITH AWS?
DNS routing is a common method for Blue Green deployments. With DNS the user can easily switch traffic from the blue environment to the green and vice versa if the rollback is needed. Route 53 can be used to implement switch when bringing up the new “green” environment. The switch could consist of a single EC2 instance, or an entire ELB. The resource record set has to be updated so that it points to the domain or subdomain of the new instance or the new ELB. It works for a varied variety of environment configurations, as long as the endpoint is a DNS service or an IP address.
As a substitute to this DNS approach, the user can also use Route 53 with designated resource record sets. The traffic can be switched from blue environment to the green environment by updating the designated record of the record set. The user can easily rollback to blue deployment in case of an error by updating the DNS record.
Another approach to perform the Blue Green switch is using the weighted distribution with Route 53. Here the user can shift the traffic based on weightage of environment. Amazon Route 53 enables the user to define a percentage of traffic for the green environment and gradually update the weights until the green environment carries the full production traffic. This method provides the ability to perform canary analysis that slowly introduces a small percentage of production traffic to the new environment.