Tutorial: Create a virtual machine scale set and deploy a highly available app on Windows

Applies to: ✔️ Windows VMs ✔️ Flexible scale sets

Virtual machine scale sets with Flexible orchestration let you create and manage a group of load balanced VMs. The number of VM instances can automatically increase or decrease in response to demand or a defined schedule.

In this tutorial, you 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.

Scale Set overview

Scale sets provide the following key benefits:

  • Easy to create and manage multiple VMs
  • Provides high availability and application resiliency by distributing VMs across fault domains
  • Allows your application to automatically scale as resource demand changes
  • Works at large-scale

With Flexible orchestration, Azure provides a unified experience across the Azure VM ecosystem. Flexible orchestration offers high availability guarantees (up to 1000 VMs) by spreading VMs across fault domains in a region or within an Availability Zone. This enables you to scale out your application while maintaining fault domain isolation that is essential to run quorum-based or stateful workloads, including:

  • Quorum-based workloads
  • Open-source databases
  • Stateful applications
  • Services that require high availability and large scale
  • Services that want to mix virtual machine types or leverage Spot and on-demand VMs together
  • Existing Availability Set applications

Learn more about the differences between Uniform scale sets and Flexible scale sets in Orchestration Modes.

Create a scale set

Use the Azure portal to create a Flexible scale set.

  1. Open the Azure portal.
  2. Search for and select Virtual machine scale sets.
  3. Select Create on the Virtual machine scale sets page. The Create a virtual machine scale set will open.
  4. Select the subscription that you want to use for Subscription.
  5. For Resource group, select Create new and type myVMSSRG for the name and then select OK. Project details.
  6. For Virtual machine scale set name, type myVMSS.
  7. For Region, select a region that is close to you like East US. Name and region.
  8. Leave Availability zone as blank for this example.
  9. For Orchestration mode, select Flexible.
  10. Leave the default of 1 for fault domain count or choose another value from the drop-down. Choose Flexible orchestration mode.
  11. For Image, select Windows Server 2019 Datacenter - Gen 1.
  12. For Size, leave the default value or select a size like Standard_E2s_V3.
  13. For Username, type the name to use for the administrator account, like azureuser.
  14. In Password and Confirm password, type a strong password for the administrator account.
  15. On the Networking tab, under Load balancing, select Use a load balancer.
  16. For Load balancing options, leave the default of Azure load balancer.
  17. For Select a load balancer, select Create new. Load balancer settings.
  18. On the Create a load balancer page, type in a name for your load balancer and Public IP address name.
  19. For Domain name label, type in a name to use as a prefix for your domain name. This name must be unique.
  20. When you are done, select Create. Create a load balancer.
  21. Back on the Networking tab, leave the default name for the backend pool.
  22. On the Scaling tab, leave the default instance count as 2, or add in your own value. This is the number of VMs that will be created, so be aware of the costs and the limits on your subscription if you change this value.
  23. Leave the Scaling policy set to Manual. Scaling policy settings.
  24. When you are done, select Review + create.
  25. Once you see that validation has passed, you can select Create at the bottom of the page to deploy your scale set.
  26. When the deployment is complete, select Go to resource to see your scale set.

View the VMs in your scale set

On the page for the scale set, select Instances from the left menu.

You will see a list of VMs that are part of your scale set. This list includes:

  • The name of the VM
  • The computer name used by the VM.
  • The current status of the VM, like Running.
  • The Provisioning state of the VM, like Succeeded.

Table of information about the scale set instances.

Enable IIS using RunCommand

To test the scale-set, we can enable IIS on each of the VMs using the Run Command.

  1. Select the first VM in the list of Instances.

  2. In the left menu, under Operations, select Run command. The Run command page will open.

  3. Select RunPowerShellScript from the list of commands. The Run Command Script page will open.

  4. Under PowerShell Script, paste in the following snippet:

    Add-WindowsFeature Web-Server
    Set-Content -Path "C:\inetpub\wwwroot\Default.htm" -Value "Hello world from host $($env:computername) !"
  5. When you are done, select Run. You will see the progress in the Output window.

  6. Once the the script is complete on the first VM, you can select the X in the upper-right to close the page.

  7. Go back to your list of scale set instances and use the Run command on each VM in the scale set.

Open port 80

Open port 80 on your scale set by adding an inbound rule to your network security group (NSG).

  1. On the page for your scale set, select Networking from the left menu. The Networking page will open.
  2. Select Add inbound port rule. The Add inbound security rule page will open.
  3. Under Service, select HTTP and then select Add at the bottom of the page.

Test your scale set

Test your scale set by connecting to it from a browser.

  1. One the Overview page for your scale set, copy the Public IP address.
  2. Open another tab in your browser and paste the IP address into the address bar.
  3. When the page loads, take a note of the compute name that is shown.
  4. Refresh the page until you see the computer name change.

Delete your scale set

When you are done, you should delete the resource group, which will delete everything you deployed for your scale set.

  1. On the page for your scale set, select the Resource group. The page for your resource group will open.
  2. At the top of the page, select Delete resource group.
  3. In the Are you sure you want to delete page, type in the name of your resource group and then select Delete.

Next steps

In this tutorial, you created a virtual machine scale set. You learned 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.

Advance to the next topic to learn more about load balancing concepts for virtual machines.