Azure Virtual Machine Scale Set Agents | VMSS — DevOps

Always learning
6 min readMar 3, 2024

Azure agent is a software agent that automates the management of Azure services. Azure agent can be used to manage resources such as virtual machines, storage, and networks in Azure. Azure agent can also be used to automate the deployment of applications and services in Azure.

Three types of Agent

  1. Microsoft-hosted agents
  2. Self-hosted agents
  3. Azure Virtual Machine Scale Set agents

Agents hosted and managed by Microsoft.

Agents that you configure and manage, hosted on your VMs.

A form of self-hosted agents, using Azure Virtual Machine Scale Sets, that can be auto-scaled to meet demands.

buymeacoffee ☕ 👈 Click the link

  1. Create a Virtual Machine Scale Set
  2. Configure Agent Pools in Azure DevOps
  3. Configure the Pipeline
  4. Configure the Custom Script Extension

Creating a VMSS in the Azure portal. Select the resource group (or) create a new one, enter the name of the VMSS, and select the region where you want to run the virtual machine.

In the Orchestration mode make sure you select the Uniform mode, then select the Image and VM architecture.

Instance count which is the number of virtual machines you want to run in your VMSS.

Finally, after passing the final validation, click on the Create button at the bottom.

Successfully crated a VMSS

Configure Agent Pools in Azure DevOps

Agent pools are scoped to the entire server. So you can share the agent machines across projects and collections.

Agent pool jobs run a job on a single agent. If you need to run a job on all agents, such as a deployment group for classic release pipelines, see Provision deployment groups.

Three types of Agent Pool

  1. Microsoft hosted agent
  2. Self-hosted
  3. Azure Virtual Machine Scale Set

Microsoft-hosted agents can run jobs directly on the VM (or) in a container. Azure Pipelines provides a predefined agent pool named Azure Pipelines with Microsoft-hosted agents.

Self-hosted Agents is an agent that you set up and manage on your own to run jobs is a self-hosted agent. You can use self-hosted agents in Azure Pipelines (or) Azure DevOps Server, formerly named Team Foundation Server (TFS).

Self-hosted agent install

Self-hosted agents give you more control to install dependent software needed for your builds and deployments.

Azure Virtual Machine Scale Sets let you create and manage a group of load balanced VM’s.

The number of VM instances can automatically increase (or) decrease in response to demand or a defined schedule.

Go to Project Settings under Pipelines and click on Agent Pools. Add agent pool select New and under the drop-down menu select Azure virtual machine scale set.

Select the service connection created in previous steps under Azure subscription, and select VMSS created in Step 1, check the Automatically tear down virtual machines after every use in Pool options. Enter the number of virtual machines you need in the scale set are per your requirement.

Now, enter the number of agents to keep on standby. I am taking 1 agent but you can change it as per your requirement. Enter the delay in minutes which will help in deleting the agents when there is no job running this will help in cost optimization of resources.

Also, check the Grant access permission to all pipelines box and then click on the Create button.

Azure virtual machine (VM) extensions are small applications that provide post-deployment configuration and automation tasks on Azure VMs

The custom script extension for VMSS can download a script and execute it on a VMSS.

To check the VMSS agent pool connection, go to the Agent pools again select the agent pool you created in previous steps, and go to the Agents tab you will see an agent is showing online this is because we chose one standby agent even if there is no job running.

Once, you have multiple jobs running you will see agents here running jobs, and once the task is completed it will automatically delete and shut down the VMs.

Go to the Virtual machine scale set in the Azure portal and go to instances, select the running instances scroll to the right, and check if “Yes” is marked under the Latest model if it’s not then Upgrade the VM. After upgradation, you will see the agent online in Azure agent pools.

Azure Pipelines is a cloud-based solution by Microsoft that automatically builds and tests code projects. Modify the pipelines

Save and run the pipeline

Some error found let’s go the custom script extension

Node package manager (npm) is a package manager and a software register but it’s also a place where developers can find, build and manage code packages.

First check the VMSS machine the npm installed (or) not

Custom script extension add

Click Browse there is no storage account. So we need to create a Storage account.

(OR)

You can use this command line box for single command executing the machine.

apt install npm

Provide a storage account name

Create a Container

upload a file

Select and create a Custom script

NPM not installed upgrade the virtual machine

Once upgrade is done finally check the npm installed?

Thank you 🙏 for taking the time to read our blog.

--

--

Always learning

கற்றுக் கொள்ளும் மாணவன்...