Virtual Machine Scale Sets : Azure

Sachin Modi
5 min readJan 9, 2021

Earlier days or era before cloud technologies where CPU utilization or Memory where your application is deployed, was going over some certain percentage or let’s say 90%, system administrator used to receive an alert as configured in system to either increase the CPU size or deploy an additional identical machine and deploy the same application in the additional machine to run the application smooth and avoid any performance issue, but again this a tedious and manual task.

Azure provides a service called virtual machine scale set (VMSS) which will automatically spin up an identical virtual machine based on demand.

To do this we have to define the virtual machine that will be part of scale set and then we define scaling condition.

Now let’s do an exercise to create a VMSS.

Type Virtual Machine Scale Sets in your azure portal search bar and then click on Add.

in the networking section edit the network interface to disable the public IP address and allow the ports as required. Please note I am disabling the Public IP because I will be putting this VMSS behind a public load balancer.

click on OK and check the use the load balancer in networking section, again this is optional and depend on your application infrastructure architecture.

Click on next in Scaling tab, here you can define how many initial VM you want to create as part of VMSS.

You can enable the health probe for the virtual machine which will be part of the VMSS. In this case since I have enable the port number as 80, it will check if IIS is running in the virtual machine or not and based on that it will mark the machine healthy or unhealthy.

You also an option to select automatic repairs service under health tab which is used to create a new machine for the marked unhealthy machine. You can provide the grace period for this.

Go head on next and then click on create.

Once VMSS has created, you can go to Instances under your newly created VMSS and you will notice the health state as Unhealthy, This is because there is no IIS server or anything on port 80 currently running on these instances.

We can install IIS server on VMSS using custom script extensions.

I already have custom script PowerShell script uploaded in azure blob account.

This url will be require while issuing the command in PowerShell.

Once you successfully issue the command in cloud shell to install the IIS server you can go to instances in VMSS and click on upgrade.

Post upgrade you will notice your instance as healthy.

Here you go, you have successfully created a VMSS and installed custom script extension in that VMSS.

Now I am going show you how to automatic repair the VM if the health goes unhealthy. For this first I will be manually uninstalling the IIS server to make the machine unhealthy. Since we don’t have any public IP address assigned to the instance I will be going to NAT rule in load balance and using that I will connect to the machine. Once you uninstall the IIS server from the machine you will notice the health state will be Unhealthy again.

Since we had already enabled the automatic repair policy while creating the VMSS and set the grace period of 30 minutes, so let’s wait until that and we will see the status.

After sometimes, you will notice that it will automatically create a new instance in which IIS server will be already installed.

Here you go, you have successfully tested the auto repair functionality in VMSS.

Now I am going to show you how to configure the automatic scaling in VMSS, for this you will need click Scaling in your VMSS and then you can customize the scaling rule. select Custom auto scale , here you can limit minimum and maximum instance and add the rule.

For this exercise purpose, I have created a queue storage service to simulate the scaling condition.

After sometimes, instances will be created based on rule added in scaling condition.

Here you go, Instances have been created successfully and you have tested the scaling functionality in VMSS.

Please follow me in LinkedIn :

https://www.linkedin.com/in/sachin-modi-%E2%98%81-6b16b947/

--

--