Virtual Machine Scale Set

Gayatri BarhateGayatri Barhate
6 min read

Table of contents

Virtual Machine Scale Set creates a group of load-balanced VMs. The number of VMs can increase or decrease in response to demand or a defined schedule.

Scale Set creates the required number of VMs in one go, you don't have to do it create VMs individually. It provides auto-scaling. We will discuss all the important features that this service provides in the further tutorial.

In this tutorial, you will deploy a virtual machine scale set in Azure and learn how to:

  • Create a resource group.

  • Create a Flexible scale set with a load balancer.

  • Add IIS to the scale set instances using the Run command.

  • Open port 80 to HTTP traffic.

  • Test the scale set.

Now let's see how it is done!

  1. Log in to your Azure Portal. Create a resource group. A resource group is like a folder in which you are going to store and manage your resources. Basically when you perform a practical related to any service like a virtual machine scale set, create a resource group and put all the resources in that group, so that resources are easy to manage for example if you want to delete all resources, you do not have to delete one by one you can just delete the resource group and all the resources inside that will be deleted.

    Enter any suitable resource group name and the region where you want to deploy/locate (for example store in the East US region) your resource group and also deploy all the resources for this practice in that region only. Then click on Review+create which checks the validation and then click on create to finally deploy the validated resource.

Create a VM Scale Set (scale up and scale down that is increase and decrease the number of VMs according to demand)

Search for Virtual Machine Scale Set and click on Create.

Choose your subscription and resource group. Enter the scale set name and choose the region.

Orchestration: It means controlling things to get the desired effect and you have greater control over virtual machines. There are two modes Uniform and Flexible. The uniform mode uses identical VM instances and is optimized for large-scale stateless workloads. Flexible mode allows you to achieve high availability at scale with identical or multiple virtual machine types. Choose the OS image, you can choose any OS. I am choosing Windows Server 2016 Datacenter.

The orchestration mode is defined when you create the scale set and cannot be changed or updated later.

Enter credentials for the VMs, you can connect to all the VMs in the scale set using this credentials. Switch to Networking tab and select the default VNet that was created in the resource group or it gets selected automatically.

Scroll down and go to load balancing, select Azure load balancer and select a load balancer, as we dont have any load balancer to use in our resource group let's create a load balancer.

Just enter the load balancer name and select public load balancer . With public load balancer anyone can connect to the load balanced VMs. Leave other configurations as it is .

In load balancer rule both the port and backend port are HTTP. A load balancer rule distributes incoming traffic across the backend pool. Inbound NAT rule forwads the traffic to a specific VM.

Switch to Scaling tab.

It asks you to enter initial instance count means how many VMs you want initially and then they will increase and decrease as per the demand, we will set to 3. In the Scaling section we have two options to go with Manual and Autoscaling. If you select manual scaling then you have to configure manually whenever needed and if you select autoscaling it will be done automatically.

Set minimum and maximum instances it means when auto scaling happens the count cannot go above 10. There is also scaling mode, you can scale based on CPU available or based on a schedule. As we are scaling based on CPU metrics if the CPU is largely available then it will scale out (increase) otherwise scale in (decrease). The scale-out rule is triggered when the Virtual Machine Scale Set's average percentage CPU metric is greater than 75 percent for the past 10 minutes. The scale-in rule is triggered when the Virtual Machine Scale Set's average percentage CPU metric is is less than 25 percent for the past minute.

Now we are done, click on Review+Create and then once the validation check is passed create the scale set.

And that's how we have successfully deployed a Virtual Machine Scale Set.

  1. Next, we will add IIS to VM instances of the scale set. It means we have to convert those 3 VMs into a web server. IIS stands for Internet Information Services, it is a web server. There are two ways to do this either you can connect to each VM instance and add IIS or use the run command on the Azure portal.

    I will show you how to do it for one VM instance in the scale set and do it for the rest of the VM instances.

    Go to Instance in the scale set.

    select any VM.

    Under operations, click on the Run command.

    Click on RunPowerShellScript and it will open a command line.

    Enter the following script into the command line and run it.

     Add-WindowsFeature Web-Server
     Set-Content -Path "C:\inetpub\wwwroot\Default.htm" -Value "Hello world from host $($env:computername) !"
    

    You should see similar output as above.

    You will understand what the script says if you add IIS manually. You can follow this blog Azure Virtual Network where you can see how to add IIS to a VM.

    1. Open port 80 to HTTP which will allow us to access the VMs on our browser. Go to the networking tab and add an inbound port rule and select HTTP service and add.

      1. Let's test the scale set now. Go to the scale set and copy the public IP into any browser.

        Keep refreshing the browser every few minutes and you can see both servers responding. I hope now you understand what is scale set is and why we need it.

        That's all for this blog and stay tuned for more computing services tutorials and more such tech. Make sure to subscribe to our newsletter.

        Thank you for Reading:)

        #Happy Reading!๐Ÿ‘

If you have any doubts or suggestions please comment down below - Gayatri Barhate

1
Subscribe to my newsletter

Read articles from Gayatri Barhate directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Gayatri Barhate
Gayatri Barhate

My name is Gayatri Barhate, and I am an IT professional with a focus on Azure. I enjoy exploring cloud computing concepts and sharing my insights through blogging. My writing covers various Azure topics, from basic principles to advanced features, aiming to help readers understand and leverage Azure technologies effectively. I am passionate about continuous learning and strive to create content that is both informative and accessible to all skill levels.