Azure VM Scale Sets

Azure VM Scale Sets

- 4 mins

INTRODUCTION
Azure provides a how-to guide for how to create a Virtual Machine Scale Set in their technical documentation here: Product Directory -> Azure -> Create / Manage a VM -> Create a scale set.

I was curious to see what this would look like, so I decided to set this up in my test lab and run through the process my self. I documented the steps below.

WHAT IS A VIRTUAL MACHINE SCALE SET?

Azure virtual machine scale sets automatically increase or decrease the number of load-balanced, identical VM instances in your environment in response to demand or a defined schedule. Virtual machine scale sets are ideal for scenarios that include compute workloads, big-data workload, and container workloads.

IMPORTANT TERMINOLOGY

  1. Horizontal Scaling is the proceess of adding or removing several virtual machines in a scale set.
  2. Vertical Scaling is the process of adding resources such as memory, CPU power, or disk space to VMs.
  3. Scheduled Calling, where you proactively schedule the scale set to deploy one or N number of additional instances to accomodate a spike in trrafic and the spike back down when eveything is back to normal.
  4. Autoscaling: Of the workload is variable and can't always be scheduled, you can use metric-based threshold scaling.

GOOD TO KNOW

  1. Low Priority Scaling Sets give you up to 80% off on price, but come at a trade off: no availability gaurantees. See here for more details.

HOW DOES A VIRTUAL MACHINE SCALE SET WORK?

Now that we know the key benefits and the important terminology, we are better prepared to dive into the Azure virtual machine scale set deployment process.

DEPLOYMENT PROCESS OVERVIEW

  1. Deploy the virtual machine scale set.
  2. Configure the virtual machine scale set.
  3. Test the virtual machine scale set.
  4. Configure the virtual machine scale set rules

TIME TO IMPLEMENT: 1 HOUR

DEPLOY THE VIRTUAL MACHINE SCALE SET

  1. Sign in to the Azure portal and open Azure Cloud Shell.
  2. In Cloud Shell, start the code editor and create a file named test-init.yaml.
  3. code cloud-init.yaml
  4. Add the following text to the file. This file contains configuration information to install nginx on the VMs in the scale set.
  5. #cloud-config
    package_upgrade: true
    packages:
      - nginx
    write_files:
      - owner: www-data:www-data
      - path: /var/www/html/index.html
        content: |
            Hello world - Virtual Machine Scale Set
    runcmd:
      - service nginx restart
  6. Press Ctrl+S to save the file. Then press Ctrl+Q to close the code editor.

  7. 01scaleSets
  8. Run the following command to create a new resource group named
    scaleset-rg
    for your scale set:
  9. az group create \
      --location eastus \
      --name scaleset-rg

    02scaleSets
  10. Run the following command to create the virtual machine scale set:
  11. az vmss create \
      --resource-group scaleset-rg \
      --name webServerScaleSet \
      --image UbuntuLTS \
      --upgrade-policy-mode automatic \
      --custom-data cloud-init.yaml \
      --admin-username azureuser \
      --generate-ssh-keys

CONFIGURE THE VIRTUAL MACHINE SCALE SET

Since we are working with a web server, it is important to add a health probe at port 80, this way if the server doesn’t respond it is considered unavailable. As a result, the load balancer will not route traffic to this particular server.

  1. Run the following command to add a health probe to the load balancer:
  2. az network lb probe create \
      --lb-name webServerScaleSetLB \
      --resource-group scaleset-rg \
      --name webServerHealth \
      --port 80 \
      --protocol Http \
      --path /
  3. Run the following command to configure the load balancer to route HTTP traffic to intsances in the scale set:
  4. az network lb rule create \
      --resource-group scaleset-rg \
      --name webServerLoadBalancerRuleWeb \
      --lb-name webServerScaleSetLB \
      --probe-name webServerHealth \
      --backend-pool-name webServerScaleSetLBBEPool \
      --backend-port 80 \
      --frontend-ip-name loadBalancerFrontEnd \
      --frontend-port 80 \
      --protocol tcp

TEST THE VIRTUAL MACHINE SCALE SET

  1. In the Azure portal, go to Resources Groups -> scaleset-rg.

  2. 03scaleSets
  3. Select the webServerScaleSet virtual machine scale set.
  4. Find the public IP of the the virtual machine scale set and browse to it.

  5. 04scaleSets
  6. Ensure you see the configurations made beforehand in the cloud-init.yaml file.

  7. 05scaleSets

CONFIGURE VIRTUAL MACHINE SCALE SET RULES

CREATE A SCALE-OUT RULE

  1. In the Azure portal, go to the page for the virtual machine scale set.
  2. On the virtual machine scale set page, under Settings, select Scaling.
  3. Select Custom autoscale.
  4. In the Default scale rule, ensure that the Scale mode is set to Scale based on a metric. Then select + Add a rule.
  5. On the Scale rule page, specify the following properties and values: Metric source, Time aggregation, Metric name, Time grain statistic, Operator, Threshold, Duration, Operation, Instance count, Cool down (minutes), then select Add.

  6. 06scaleSets

CREATE A SCALE-IN RULE

  1. In the Default scale rule, select + Add a rule.
  2. On the Scale rule page, specify the following properties and values: Metric source, Time aggregation, Metric name, Time grain statistic, Operator, Threshold, Duration, Operation, Instance count, Cool down (minutes), then select Add.

  3. 07scaleSets
  4. Verify the rules have saved:

  5. 08scaleSets
comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora