LCP

Are you trying to deploy a new update to the production environment? However, are you afraid of the risks involved with downtime or buggy application?

This is when Blue-Green Deployment comes to the rescue by providing a smooth transition to the new update. To understand how it is done, let us go through the blog, where we'll see what Blue-Green Deployment is, and how it can be done in the Azure cloud with a step-by-step guide.

What is Blue-Green Deployment?

Blue Green Deployment, Azure cloud deployment, Application gateway, stages of Blue Green Deployment, Production environment

Blue-Green Deployment is a technique of running two applications, that are identical, in the production environment to reduce the risk of application downtime. Here, Blue deployment is the current version of an application, and green is the next/new version to be launched.

Let us understand this by example. Suppose the current application version is 1.0 (Blue Deployment), and the future version/new version is 2.0 (Green Deployment). Right now, multiple users are using version 1.0, however, the new version is to be deployed in the production environment, and don’t want to give any downtime to the users. So to start the process, we would redirect a few users to the Green Deployment. Once it is confirmed that the new version can perform and sustain the traffic without any bugs or lag, we can redirect all users to the Green Deployment in a controlled manner.

Before starting with the Azure Blue-Green deployment, look at the following resources required for the whole process.

  1. Virtual Machine: is an azure service that connects you with your machine.
  2. Azure Database for PostgreSQL Flexi server: is hosted in a Linux-based Virtual machine that aligns with the Postgres engine architecture.
  3. Resource Group: holds related resources in Azure.
  4. V-net: represent your network
  5. Traffic Manager: This allows you to distribute public-facing applications in different regions in azure.
  6. Load balancer: provides high availability by distributing incoming traffic among healthy VMs.

There are two sets for the deployment. The first set is Blue Deployment which is your current version, and the other set is your Green deployment which is your next version of your application. Using the two different sets simultaneously helps to revert the application to the old version (Blue Deployment) if the new version (Green Deployment) cannot handle network traffic. For both sets, we have connected to the same database.

Now, we would be creating the load balancers for Blue and Green Deployments. While deploying the load balancer, attach the IP Address in the frontend pool and add the Virtual Machine to the backend pool (This step applies for both Blue and Green Deployment).

The question here is how we would know if the new version (Green Deployment) is ready for handling network traffic as expected?

We would be creating a weighted Traffic manager and attaching both load balancers to the traffic manager. Add 90% traffic to the Blue Deployment (current version) and 10% to the Green Deployment (new version) and send some user traffic requests to the traffic manager. If the output is as per the defined parameters, we can add 100% traffic to the Green Deployment.

Configuration of Blue-Green Deployment in azure cloud

How to create a Resource Group.

1. Log in to portal.azure.com, go to the resource group and click on Create a Resource Group.

Azure settings, Resource group for Blue Green Deployment, Azure subscription, Creating Azure Resource Group

2. Click on Create.

Adding tags, Azure resource group, Creating resource group, Review and create resource group

How to create Virtual Machine

Note: There are the same steps for deploying a Green deployment virtual machine.

1. Go to the Virtual Machines and click on Create.

Azure virtual machines, Linux virtual machine, Creating virtual machine

2. Add details according to your requirement.

Azure virtual machines, Linux virtual machine, Creating virtual machine, setting id password of Virtual machine, Azure Availability zone, Azure Spot Instance

3. Select Storage type and click on Next.

Azure virtual machines, Linux virtual machine, Creating virtual machine, setting id password of Virtual machine, Disk configuration, Disk encryption

4. Enter networking details and select public IP as none.

Azure virtual machines, Linux virtual machine, Creating virtual machine, setting id password of Virtual machine, Subnet, public IP, NIC network security group

5. Set management to fulfill your requirement and click on Next.

Azure virtual machines, Linux virtual machine, Creating virtual machine, monitoring, boot diagnostics, Azure site recovery, Azure AD

6. Set advanced settings as it fulfills your requirement.

Azure virtual machines, Linux virtual machine, Creating virtual machine, Extensions, VM Applications

7. Add tags (optional) and create your Virtual Machine

Azure virtual machines, Linux virtual machine, Creating virtual machine, tags, management, Review and create VM, Azure Resources

How to create Azure Database for PostgreSQL flexible servers

1. Open Azure database for PostgreSQL flexible servers and click on Create

Azure Database, PostgreSQL flexible servers, create Azure Database, Azure Resource group

2. Select a flexible server.

Azure Database, PostgreSQL flexible servers, create Azure Database, selecting flexible server, single server, hyperscale server group, Azure arc enabled PostgreSQL hyperscale

3. Select desired Resource Group, Workload type, and select postgre version. Now enter your username and generate a password

Note: Select the same Resource Group as we are using for Virtual Machine

Azure Database, PostgreSQL flexible servers, create Azure Database, project details, azure server details, PostgreSQL version

4. For the networking section, select the Private access for connectivity method. Also, select the same network as we used for the Virtual Machine.

Note: We would need a new subnet as the Virtual Machine’s subnet won't work for the Postgre flexible server.

Azure Database, PostgreSQL flexible servers, create Azure Database, creating new subnet, virtual network, private DNS integration

5. Click on Create, and you will get the following output after the successful deployment.

Azure Database, PostgreSQL flexible servers, create Azure Database, review and create, click to create azure database

How to Create Load Balancer in Azure

Note: For Green deployment as well, follow the same steps.

1. Open a service name Load Balancer in Azure and click on Create

Azure Load Balancer, creating load balancer, Azure resource group for load balancer

2. Enter a basic configuration and click on Next.

Azure Load Balancer, creating load balancer, particulars for creating load balancers, how to create load balancer in Azure

3. Click on Add frontend IP configuration and add Public IP address. (Either add an existing IP address or create a new one)

Azure Load Balancer, creating load balancer, frontend IP configuration, Public IP address

4. Select Add Backend Pools

Azure Load Balancer, creating load balancer, outbound rules, review and create load balancer

5. For adding Virtual Machine in your backend pool, select Virtual Machine and click on Add.

Note: Select the same V-net as did for the Virtual Machine.

Azure Load Balancer, creating load balancer, outbound rules, or adding Virtual Machine in your backend pool, select Virtual Machine

6. If there is a requirement of adding an Inbound or Outbound rule, then add the tags and click on Review and Create.

Azure Load Balancer, creating load balancer, outbound rules, review and create load balancer

7. After a successful deployment, you will get an output like the image below.

Azure Load Balancer, creating load balancer, successfully deployed load balancer

8. For adding the Health Probe for a health checkup, select the load balancer at the left panel, then you will see Health Probe, select and click on Add.

Azure Load Balancer, creating load balancer, health checkup, health probe

9. Add health prob for 80 port and click on Add.

Azure Load Balancer, creating load balancer, adding health probe, blue deployment health probe, protocol for health probe

How to create a Traffic manager in Azure

1. Open a service named Traffic Manager in the Azure portal and click on Create.

traffic manager in Azure, steps of traffic manager, Azure traffic manager

2. Select Weighted Routing Method and select the resource group same as every previous resource and click on Create.

traffic manager in Azure, steps of traffic manager, Azure traffic manager, Routing method, Creating traffic profile

3 After successful deployment, you will get the output same as below.

traffic manager in Azure, steps of traffic manager, Azure traffic manager, deployment of Azure traffic manager

4. Now select the traffic manager we just created, and you will be able to see Endpoints in the left panel, select and click on Add.

(Follow the same steps for adding the “Green Deployment” endpoint)

traffic manager in Azure, steps of traffic manager, Azure traffic manager, same steps for green deployment traffic manager

5. Select the Resource Group type as a Public IP address, then select the Public IP and click on Add.

(Select the same public IP Address as we added for the Frontend IP Configuration for the Load Balancer)

Note: We have added 90% for the Blue Deployment and for the rest 10% for the Green Deployment.

Blue Green deployment, Blue Green deployment endpoints, 90% to blue deployment

(For the output you will see DNS name URL at the Traffic manager’s overview section)

Note: For adding a Public IP address in the Endpoints, we need to add a DNS name in the IP Address’s configuration.

  1. Search Public IP Address
  2. Select existing IP Address
  3. On the left panel select Configuration
  4. Enter the DNS name label
  5. Click on Save

End Note

Congratulations! You've successfully deployed the new update of your application without any downtime, and the new version is running smoothly. In case of a major bug, that is not allowing the users to use it properly, you can roll back the update, work on it, and deploy it back.

We at Seaflux are your dedicated partners in the ever-evolving landscape of Cloud Computing. Whether you're contemplating a seamless cloud migration, exploring the possibilities of Kubernetes deployment, or harnessing the power of AWS serverless architecture, Seaflux is here to lead the way.

Have specific questions or ambitious projects in mind? Let's discuss! Schedule a meeting with us here, and let Seaflux be your trusted companion in unlocking the potential of cloud innovation. Your journey to a more agile and scalable future starts with us.

Jay Mehta - Director of Engineering
Jay Mehta

Director of Engineering

Claim Your No-Cost Consultation!

Let's Connect