Auto-scaling Azure virtual machines
Virtual machine scaling games
Scale sets are Azure compute resources that can be useful for deploying and managing identical VMs. They are designed to support automatic scaling of virtual machines. Therefore, VM scale sets can be created using the Azure portal, JSON templates, and REST APIs. To increase or decrease the number of VMs in the scale set, we can change the capacity property and redeploy the template. A VM set is created inside a VNET, and individual VMs in the set are not assigned public IP addresses.
Any virtual machine we deploy that’s part of a set won’t have a public IP address. Because sometimes the set of virtual machines will have a front-end load balancer that handles the load, and that will have a public IP address. We can use that public IP address and connect to the underlying virtual machines in the set of virtual machines.
Automatic scaling of virtual machines
Autoscale allows us to dynamically allocate or remove resources based on service load. You can specify the maximum and minimum number of instances to run and add or remove VMs based on a set of rules within the range.

The first step in autoscaling is to select a metric or a schedule. So, it can be metric-based autoscaling, or schedule-based autoscaling. The metric can be CPU utilization, etc., and the time can be like night at 6 AM until morning 6:00 AM, we want to reduce the number of servers. We can have schedule-based autoscaling. In case we are going to reach according to the load, then we can use metric-based autoscaling.
The next step in auto-scaling is to define a rule with the condition. For example, if the CPU usage is above 80%, we should launch a new instance. And then once the condition is met, we can perform certain actions. Consider for example adding or removing virtual machines, or sending an email to a system administrator, etc. We need to choose whether it is time-based or metric-based auto-scaling, and we need to choose the metric. We define the rule and the actions that should be triggered when the condition of this rule is present.
Horizontal and vertical scaling
- Horizontal scaling: The increase or decrease in the number of VM instances. This is automatic horizontal scaling, sometimes called “Scale-out” or “Scale-in.”
- Vertical scaling: In this case, we keep the same number of virtual machines. But we make them more or less powerful. Power is measured by memory, CPU speed, disk space, etc. Therefore, it is limited by the availability of more powerful hardware in the same region. As you might expect, this usually requires starting and stopping a VM. This is sometimes called scaling up or down. Here are the steps to perform vertical scaling.
- Set up an Azure Automation account
- Import Azure Automation Vertical scale runbooks into our subscriptions.
- Add a webhook to our network.
- Add an alert to our virtual machine.
- We can also scale web applications and cloud services.
Autoscaling measures
- Calculating Metrics: The available metrics depend on the installed operating system. For Windows, we can have CPU, memory, and logical disk metrics. For Linux, we can have CPU, memory, physical interface, and network metrics.
- Web application metrics: These include CPU and memory percentage, disk queue length, and traffic.
- Storage and Service Bus Metrics: We can measure the storage queue length. Ultimately, it’s the number of messages in the storage queue. The storage queue length is a specific metric. And the threshold applied will be the number of messages per instance.
Tools to implement autoscaling
- We can use the Azure portal to create a scaling set. We can also enable autoscaling based on a metric.
- We can provision and deploy VM scaling sets using ARM templates. (Resource Manager Templates)
- ARM templates can be deployed using Azure CLI, PowerShell, REST, and also directly from Visual Studio.
Scaling an Azure Virtual Machine
Step 1: Go to Azure Marketplace and type the virtual machine scale set. Then click Create.

Step 2: We need to give a name to this scale set. And fill in all other required details as shown in the figure below. Then click on create.

Step 3: Now your virtual machine set is successfully deployed. To view the VMSS, you can go to Resources.
Step 4: Now click on scaling. Provide an auto scaling setting name. And select the resource group.
Step 5: Scroll down and you will find two ways to autoscale. First, click “add a rule” for metric-based autoscaling. For example, we will scale our virtual machine if the average CPU utilization percentage is above 70%.
Step 6: Select the scaling based on time and date which will adapt automatically. And the last thing is Notify, where you are notified when the auto scaling is triggered.