Configure a Load Balanced VM Scale Set in Azure

1.75 hours
  • 3 Learning Objectives

About this Hands-on Lab

Welcome to this Azure hands-on lab, where we will be creating and configuring a Load Balanced Virtual Machine Scale Set (VMSS). The goal of this lesson is to gain knowledge and experience with dynamic and elastic compute using a VMSS and high availability using a load balancer. Good luck, and enjoy the hands-on lab!

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a VM Scale Set with Load Balancing

Create a VM Scale Set

Follow the instructions below for creating a Virtual Machine Scale Set:

  1. Be logged in to portal already. We did it in the Introduction video.
  2. Click on the + Create a resource option.
  3. Search for Virtual Machine Scale Set.
  4. Click on Virtual machine scale set.
  5. Click Create.

Use the following settings for creating your Virtual Machine Scale Set:

  1. Fill out Basics:
    • Subscription: The default already selected
    • Resource group: The default is already selected/existing
    • Virtual machine scale set name: vmscaleset01
    • Location: West US
    • Availability zone: None
    • Operating system disk image: Ubuntu 18.04 LTS
    • Azure Spot instance: No
    • Instance size: *Standard_D2s_v3
    • Authentication type: Password
    • Username: azureuser
    • Password: Use the password you have been provided in the credentials section
    • Click on Next: Disks >
  2. Fill out Disks:
    • OS disk type: Standard SSD
    • Encryption type: Default
    • Click on Next: Networking >
  3. Fill out Networking:
    • Virtual network: vnet1 (Use the existing vnet available in the resource group provided for you).
    • Click on the edit icon for the Network interface
      • Name: leave as the default
      • Subnet: subnet1
      • NIC network security group: None (we already have one attached to the subnet
      • Public IP address: Enabled
      • Click OK
    • Use a load balancer: Yes
    • Load balancing options: Azure load balancer
    • Leave the defaults as-is
    • Click Next: Scaling >
      1. Fill out Scaling:
    • Initial instance count: 0 (we will change this later)
    • Scaling policy: Manual (we will change this later)
      1. Click Review + create
      2. Click Create once validation is passed
      3. Navigate to the newly created VM Scale Set.

Note that there can be an error with the Azure Portal, which results in the Manual Scale being set to 2 instead of 0.

Make sure you change this to 0 before proceeding.

Configure a Custom Script Extension

To configure a Custom Script Extension, we first need to store a script file within an Azure blob container.

Follow the steps below to prepare the file:

  1. Download the file to use for your VM Extension here:
  2. Navigate to Storage Accounts.
  3. Select the storage account which was already created for you.
  4. Click Storage Explorer:
    1. Right click on Blob Containers.
    2. Click Create a blob container.
      • Name: scripts
      • Public access level: Private
      • Click Create
    3. Browse to the new container (note you may need to right click Blob Containers and choose refresh if it doesn’t appear.
    4. Click Upload.
    5. Select the file you downloaded earlier.
    6. Click Upload.

Follow the steps below to configure the Custom Script Extension for the VM Scale Set. Ensure that there are currently no instances running, or they will not have the appropriate configuration (without being upgraded).

  1. Open the recently created VM Scale Set.
  2. Click on Extensions within the Settings menu.
  3. Click on the + Add icon.
  4. Choose Custom Script For Linux.
  5. Click Create.
  6. Click on Browse to select a script file.
  7. Navigate to the scripts container you created earlier.
  8. Tick the tick-box beside the file.
  9. Click on Select.
  10. Click OK.
Configure Autoscale
  1. Navigate to Settings then Scaling.
  2. Click on the Custom autoscale option.
  3. Enter a name for the autoscale: autoscalesetting01.
  4. Leave the resource group as-is (select your resource group if it is not pre-populated).
  5. Configure the ‘Default’ autoscale profile:
    1. Leave Scale based on a metric selected.
    2. Click ‘Add a rule’, to add a rule for scaling out:
      • Scale based on the VM Scale Set
      • Criteria: average percentage CPU, greater than 70% over 5 minutes
      • Increase by 1 instance and 5 minute cool down
    3. Add a rule for scaling in:
      • Scale based on VM Scale Set
      • Criteria: average percentage CPU, less than 10% over 5 minutes
      • Decrease by 1 instance
    4. Configure instance limits: minimum of 1, maximum of 3, and default of 1.
    5. Save the settings.

We can then connect to an instance within the VMSS and use the stress tool to emulate load. The command to use is stress --cpu 1. Watch the monitoring of the VMSS and confirm that your instance count increases.

Additional Resources

Log in to the live environment with the Azure Labs credentials provided.

Make sure you are using the same region as your lab-provided resource group throughout the hands-on lab.

Follow the learning objectives listed below. Attempt to follow the steps first, without the videos, and then use the videos and/or lab guide to verify the solution.

Note: When configuring teh VM sacle set, use the instance type of Standard_D2s_v3. To connect to the VMSS instances for test purposes, use the following information:

  • Username: azureuser.
  • Password: Use the one provided in the credentials section.

Then, log in to the VM via SSH:

ssh azureuser@<VM PUBLIC IP>

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?