Create a Load Balanced VM Scale Set in Azure

Get Started
1.75 hours
  • 3 Learning Objectives

About this Hands-on Lab

**Note: Microsoft have made a number of changes to the Azure Portal and VM Scale Set creation experience. You can continue to use this lab, however, please be aware that this lab is out-of-date and is in the process of being re-created.**

Welcome to this Azure learning activity, where we will be creating and configuring Load Balancing for a Virtual Machine Scale Set (VMSS).

The goal of this lesson is to gain knowledge and experience with:
* Dynamic and elastic compute using a VMSS
* High availability using a Load Balancer

Good luck and enjoy the Learning Activity!

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create and Configure a VM Scale Set

Create a VM Scale Set

NOTE: See this link for more information on VM scale set instance IDs: https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-instance-ids

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

  • Be logged in to portal already. We did it in the Introduction video.
  • Click on the green + sign to create a new resource.
  • Search for Virtual Machine Scale Set.
  • Click on Virtual machine scale set.
  • Click Create.

The following are the settings used in the video, but you may use whatever settings you wish:

  • Subscription: The default already selected
  • Resource group: The default is already selected/existing
  • Virtual machine scale set name: vmscaleset01
  • Location: West US
  • Operating system disk image: Ubuntu 16.04 LTS
  • Instance size: A0 (You may need to turn off all filters in order to see this size)
  • Authentication type: Password
  • Username: azureuser
  • Password: Use the password you have been provided in the credentials section
  • Use managed disks: Yes
  • Virtual network: VNET1
  • Subnet: subnet1
  • Load balancing option: None (we will change this later)
  • Public IP address per instance: On
  • Instance count: 0 (we will change this later)
  • Autoscale: Disabled (we will change this later)

Configure a VM Extension (Custom Script for Linux):

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 script.sh file:

  • Download the file to use for your VM Extension here: https://raw.githubusercontent.com/linuxacademy/content-az300-lbvmscaleset/master/script.sh
  • Navigate to Storage Accounts
  • Select the storage account which was already created for you
  • Click Storage Explorer
    • Right click on Blob Containers
    • Click Create a blob container
    • Name: scripts
    • Public access level: Private
    • Click Create
    • Browse to the new container (note you may need to right click Blob Containers and choose refresh if it doesn’t appear
    • Click Upload
    • Select the script.sh file you downloaded earlier
    • 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).

  • Open the recently created VM Scale Set
  • Click on Extensions within the Settings menu
  • Click on the + Add icon
  • Choose Custom Script For Linux
  • Click Create
  • Click on Browse to select a script file
  • Navigate to the scripts container you created earlier
  • Tick the tick-box beside the script.sh file
  • Click on Select
  • Click OK
Configure Autoscale
  • Navigate to Settings > Scaling > Custom autoscale
  • Enter a name for the autoscale: autoscalesetting01
  • Leave the resource group as-is (select your resource group if it is not pre-populated)
  • Configure the ‘Default’ autoscale profile:
    • Leave Scale based on a metric selected
    • 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, 5 minute cool down
    • 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
    • Configure instance limits: minimum of 1 and maximum of 3

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.

Configure Load Balancing
  • Create load balancer:
    • Type: Public
    • SKU: Basic
    • Public IP: Use existing public IP
  • Configure the public load balancer:
    • Create a backend pool, and associate to the VMSS
    • Create a health probe using HTTP port 80 using the defaults
    • Add a load-balancing rule using TCP/80 and the backend pool + health probe
  • Ensure you upgrade your VMSS for the load balancer association to take effect
  • Test using the public IP of the load balancer

Additional Resources

Note: Microsoft have made a number of changes to the Azure Portal and VM Scale Set creation experience. You can continue to use this lab, however, please be aware that this lab is out-of-date and is in the process of being re-created.

Instructions

Please go ahead and log in to the live environment with the Azure Labs credentials provided.

Make sure you are using West US as the region throughout the learning activity.

Follow the steps below. Attempt to follow the steps first, without the videos, and then use the videos to verify the solution.

Note: To connect to the VMSS instances for test purposes, use the following information:

  • For a username, use azureuser.
  • For the password, use the one that is provided in the credentials section.
  • Now log into the VM with SSH using: ssh azureuser@<VM PUBLIC IP>

Click the question marks below to view more details for each task.

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?