Blue-green deployment using NetScaler VPX and Azure pipelines
Blue-green deployment is a technique that reduces downtime and risk by running two identical production environments called blue and green. At any time, only one of the environments is live that serves all the production traffic. The basis of the blue-green method is side-by-side deployments of two separate but identical environments. Deploying an application in both the environments can be fully automated by using jobs and tasks. This approach enforces duplication of every resource of an application. However, there are many different ways blue-green deployments can be carried out in various continuous deployment tools. This topic provides information on how to achieve the blue green deployment of an application (non cloud-native applications) using NetScaler with Azure pipelines. Azure pipelines are a cloud service provided by Azure DevOps which allows you to automatically run builds, perform tests, and deploy code to various development and production environments.
In this solution, NetScaler VPX is deployed on the Azure platform to enable load balancing of an application and achieve blue green deployment using NetScaler VPX. For more information on how to deploy NetScaler on Microsoft Azure, see the NetScaler documentation.
Why blue-green deployment?
The following are the major benefits of adopting Blue green deployment strategy in the application life cycle.
- seamless switch between the blue and green version of applications
- zero-downtime upgrade for an existing application
- easier rollback mechanism, implementation, and disaster recovery
Blue-green deployment using NetScaler
Blue-green deployment of an application can be achieved using NetScaler by adjusting the traffic split percentage of the application end points (blue and green versions) to zero and 100. Initially, the traffic split percentage of an application with blue version is set to 100 and post validation of the green version, you change the traffic split percentage of the blue version to zero and set the green version to 100. At this stage, the green version is promoted to the live environment as a blue version and further upcoming versions of the application are treated as the new green versions.
Here, you are using the content switching (CS) policy in NetScaler for each application version. You can achieve the blue green deployment by adjusting the traffic weight and priority of the CS policy to switch the traffic between blue and green versions of the application.
Blue-green deployment using NetScaler with Azure pipelines
Citrix proposes a solution for blue-green deployment using NetScaler with Azure pipelines for any virtual machine based application as depicted in the following topology.
For information on how to create and configure agent pools on Azure, see the Azure documentation.
In this solution, there are three configuration directories:
adc_configs
deployment_configs
pipeline_configs
adc_configs
This directory includes the template based Terraform scripts which are responsible for pushing application(version) specific NetScaler configuration such as back-end services, traffic weight. The NetScaler configurations include creating content switching virtual server, load balancing virtual server, and a content switching policy with the appropriate priority set for each version of the application.
deployment_configs
This directory includes the setup_config
and teardown_config
JSON files that specify the version of the application to be deployed or brought down respectively during blue-green deployment. This directory also includes configuration files with back-end service IP addresses.
pipeline_configs
This directory includes the Azure pipeline script and the python script which reads the user configurations and triggers the pipeline based on the user request to introduce a new version or switch the traffic between blue and green version of the application or teardown a version of an application.
Deploying a sample application using blue-green mode in Azure Pipelines
This procedure shows the steps to deploy an application using blue-green mode in Azure pipelines.
Before you perform the steps ensure that:
- NetScaler VPX is deployed on the Azure platform
- Back end services are running on the virtual machine and the corresponding IP addresses are available to set up the continuous delivery.
Perform the following steps:
-
Clone the GitHub repository and go to the directory
cd/blue-green
. -
Review and update the NetScaler configurations in the Terraform files under the
adc_configs
directory. -
Create two Azure pipelines using the existing YAML files,
deploy.yaml
andteardown.yaml
, for deploying and tearing down the applications. See, Azure pipelines for creating a pipeline. -
Update the subscription details and agent pool details in the pipeline YAML and then save the pipeline.
-
Create
v1.conf
under thedeployment_configs
directory as follows:backend_service_ip = "<IP of backend service with version v1>" priority = 101
Note: This configuration is used to set the priority of the traffic to be served by NetScaler when you introduce a new version of the application in production environment.
-
Update the
setup_config.json
file with version and traffic weight percentage.{ "TRAFFIC_WEIGHT": "100", "ADC_CONFIG": "cd/blue-green/deployment_configs/v1.conf", "DEPLOYMENT_VERSION": "v1" }
-
Commit
setup_config.json
andv1.conf
files using Git to trigger the pipeline to deploy the v1 version of the application. -
Access the application through NetScaler.
-
Introduce the v2 version of the application by creating the
v2.conf
file.backend_service_ip = "<IP of backend service with version v2>" priority = 100 /* This configuration should be lesser than the v1 version of application, in order to set the higher priority to the traffic served by version v2.*/
-
Deploy the version v2 of the application by updating
setup_config.json
.{ "TRAFFIC_WEIGHT": "0", "ADC_CONFIG": "cd/blue-green/deployment_configs/v2.conf", "DEPLOYMENT_VERSION": "v2" } At this point, the traffic is served by version v1 of the application because the traffic weight is set as zero for version v2.
-
Update the traffic weight for version v2 to 100 by updating the
setup_config.json
file.{ "TRAFFIC_WEIGHT": "100", "ADC_CONFIG": "cd/blue-green/deployment_configs/v2.conf", "DEPLOYMENT_VERSION": "v2" }
-
Since the traffic is switched to version v2, you can tear down the version v1 by updating the file
deployment_configs/teardown_config.json
as follows:{ "DEPLOYMENT_VERSION": "v1" }
Once the pipeline build is completed, version v1 of the deployment is torn down and only version v2 is running.
Note:
You can continue introducing newer versions by following the same steps as followed for version v2.
Canary deployment
Blue-green solution can be also used to achieve canary deployment for your application and the steps remains same as in the blue-green deployment.
To achieve the canary deployment, you need to set the TRAFFIC_WEIGHT
to the desired traffic percentage that you want to route to the v2 version of the application.
For example, as per the following configuration 20 percentage of the traffic goes to the v2 version of application and the remaining 80 percentage of the traffic continues to get routed to the older version (v1) of the application without any manual intervention.
{
"TRAFFIC_WEIGHT": "20",
"ADC_CONFIG": "cd/blue-green/deployment_configs/v2.conf",
"DEPLOYMENT_VERSION": "v2"
}