title | layout | sidebar | permalink | folder |
---|---|---|---|---|
Deploying to Azure VM using Deployment Groups |
page |
vsts2 |
/labs/vstsextend/deploymentgroups/ |
/labs/vstsextend/deploymentgroups/ |
In the earlier versions of Azure DevOps, if the application needed to be deployed to multiple servers, the Windows PowerShell remoting had to be enabled manually, the required ports opened and the deployment agent installed on each of the servers. The pipelines had to be managed manually if a roll-out deployment was required.
All the above challenges have been handled seamlessly with the introduction of the Deployment Groups{:target="_blank"}.
The Deployment Group installs a deployment agent on each of the target servers in the configured group and instructs the Release Pipeline to gradually deploy the application to all these servers that belong to the Deployment Group. Multiple pipelines can be created for the roll-out deployments so that the latest version of the application could be provided in a phased manner to the multiple user groups for validating the newly introduced features.
This lab covers the configuration of the deployment groups and details how the deployment groups could be used in the Azure DevOps.
-
Refer to the Getting Started page to know the prerequisites for this lab.
-
Click the Azure DevOps Demo Generator link and follow the instructions in Getting Started page to provision the project to your Azure DevOps.
The following resources will be provisioned on the Azure using an ARM template:
-
Six Virtual Machines (VM) web servers with IIS configured
-
SQL server VM (DB server)
-
Azure Network Load Balancer
-
Click on the Deploy to Azure button to initiate the resource provisioning. It takes approximately 10-15 minutes to complete the deployment. Provide all the necessary information as is shown.
-
Once the deployment is successful, the list of all the resources will be displayed on the Azure Portal.
-
Click on the DB server VM which has sqlSrv in its name to view the details.
-
Make a note of the
DNS
name. This value will be required later in an exercise.
The Azure DevOps makes it easier to organize the servers for deploying the applications. A deployment group is a collection of machines with a deployment agent on each of them. Each of the machine interacts with the Azure DevOps to coordinate the deployment of the app.
Since there is no configuration change required for the build pipeline, the build will be triggered automatically after the project is provisioned.
-
From the pipelines, select the Deployment Groups{:target="_blank"} option. Click on the Add a deployment group button to configure.
-
Provide a Deployment group name of your choice and click on the Create button. A registration script generated will be displayed.
The target servers will be available in the deployment group for deploying the application. You can register the target servers using the script above. In this lab, we automatically register our target servers in the release pipeline. The release definition uses Phases to deploy the application to the target servers. A Phase{:target="_blank"} is a logical grouping of the tasks that defines the runtime target on which the tasks will execute. A deployment group phase executes tasks on the machines defined in a deployment group.
-
Naviagate to Pipelines | Releases. Select the release pipeline and click Edit.
-
In the pipeline select the stage Dev from the tasks dropdown to view the deployment tasks in pipeline.
-
The tasks will be grouped under the Agent phase, Deployment group phase and IIS Deployment phase.
-
Agent Phase: In this phase, the target servers will be associated to the deployment group using the Azure Resource Group Deployment task.
-
Azure Resource Group Deployment: This task will automate the configuration of the deployment group agents to the web and db servers.
-
Authorize the correct Azure subscription from the drop down or click Manage to associate a new Azure subscription.
-
Choose the Resource Group that was created previously in Azure Portal.
-
In the Azure Pipelines service connection, click + New to create a new service connection of your Azure DevOps account.
-
With the Token Based Authentication, provide the Name, Azure DevOps URL and PAT. Then click Verify and save.
-
Choose the Team Project that was provisioned with Azure DevOps Demo Generator tool.
-
Choose the Deployment Group.
-
-
-
Deployment group phase: This deployment group phase executes tasks on the machines defined in the deployment group. This phase is linked to the db tag. Choose the Deployment Group from the drop down.
-
IIS Deployment phase: In this phase, the application will be deployed to the web servers using the below tasks. This phase is linked to web tag. Choose the Deployment Group from the drop down.
-
Azure Network Load Balancer: As the target machines are connected to the NLB, this task will disconnect the machines from the NLB prior to the deployment and reconnect them back to the NLB after the deployment.
-
IIS Web App Manage: The task runs on the deployment target machine(s) registered with the Deployment Group configured for the task/phase. It creates a webapp and application pool locally with the name PartsUnlimited running under the port 80
-
IIS Web App Deploy: The task runs on the deployment target machine(s) registered with the Deployment Group configured for the task/phase. It deploys the application to the IIS server using Web Deploy.
-
The number of concurrent deployments can be controlled by setting the value in the Maximum number of targets in parallel field. For example, in this lab, since there are 6 web servers, setting the target servers to 50% will deploy the build artifacts to 3 web servers in parallel at a time.
-
-
Select the Disconnect Azure Network Load Balancer task and provide the following details:
-
Azure Subscription: Choose the associated Azure subscription from the drop down.
-
Resource Group: Name of the Resource Group which was created while provisioning the environment.
-
Load Balancer Name: Select the name from the dropdown.
-
Action: Set the action to Disconnect Primary Network Interface
-
-
Select the Connect Azure Network Load Balancer task and provide the following details:
-
Azure Subscription: An ARM Endpoint created in the Exercise 1
-
Resource Group: Name of the Resource Group which was created while provisioning the environment
-
Load Balancer Name: Select the name from the dropdown
-
Action: Set the action to Connect Primary Network Interface
-
-
Click on the Variables tab and select the Pipeline Variables option. Enter the variable values as below
Variable Name Variable Value DatabaseName PartsUnlimited-Dev DBPassword P2ssw0rd@123 DBUserName sqladmin DefaultConnectionString Data Source=YOUR_DNS_NAME.cloudapp.azure.com;Initial Catalog=PartsUnlimited-Dev;User ID=sqladmin;Password=P2ssw0rd@123;MultipleActiveResultSets=False;Connection Timeout=30; ServerName localhost {% include important.html content= "Make sure to replace your SQL server DNS name (which you noted from Azure Portal earlier) in DefaultConnectionString variable" %}
It will look like as below
Your DefaultConnectionString will be like as below after replacing SQL DNS.
Data Source=dgsqlw4zktxlvx7ddu.centralindia.cloudapp.azure.com;Initial Catalog=PartsUnlimited-Dev;User ID=sqladmin;Password=P2ssw0rd@123;MultipleActiveResultSets=False;Connection Timeout=30;
-
Save the changes and click on the Create release then Create
-
Once the release is completed, the deployments will be completed in the DB and Web servers. Click on the logs to view the release summary.
-
In the Azure Portal, click the DNS of any web application instance, to access the application.
{% include important.html content= "The Azure Load Balancer{:target="_blank"} will distribute incoming traffic among healthy instances of servers defined in a load-balanced set. Hence the DNS of all web server instances will be the same." %}
-
The deployed web application will be launched and the various features can be browsed.
Since the lab uses multiple virtual machines and other resources, ensure you delete the resource group after the lab completion to avoid incurring charges.
Using Azure DevOps and Azure, the web applications can be easily compiled and deployed to multiple target servers using Deployment Groups.