Autoscales

How to Create Autoscales in Microsoft Azure Using Templates

972 VIEWS

· · ·

Microsoft Azure offers an interface that will allow you to build a default autoscale, a load balancer, and lots of other resources. But if you need customization, the interface isn’t enough—The creation of a JSON template is required.

In my case, I needed to customize an autoscale with these requirements:

  1. Create a load balancer that works with HTTPS.
  2. Use my VHD to launch new VMs.
  3. Add metrics of memory utilization to scale the VMs. By default, the autoscale has only CPU metrics.

Creating the VHD

The first thing needed is to generate the VHD from the VM that we want to use as the base to autoscale. In this example, I used a Linux VM with Ubuntu Server, but the OS is not important just to create VHD. To generate the VHD, you can follow the instructions in this post: Capture a Linux virtual machine running on Azure.
Theses steps will generate a JSON that contains the path of your VHD. Find it inside to “storageProfile” > “image” > “uri”.

Creating the JSON template

There are amazing, helpful templates available in Azure Quickstart Templates. To build my template, I looked into every VMSS (Virtual Machine Scale Set) template and configured it to work as I wanted. That was the most boring part…

This is the final version of the template. Now let’s see how to customize it.

Parameters
The template has some parameters that will be asked in the moment of deploy:

  1. vmSku: Size of VMs used in the autoscale. I chose Standard_F1s, but there are many other options.
  2. vmssName: Name of VMSS resource—This needs to be short (about 6 characters) because it will be used as a prefix in other resources.
  3. instanceCount: Amount of VMs used in autoscale. A good option is to use 15 as the maximum.
  4. adminUsername: This needs to be the same user that you had in the original VM used to generate the VHD.
  5. adminPassword: Same here. Use the exact password from the original VM.

1. Load Balancer

To enable HTTP and HTTPS, it’s necessary to add two inboundNatPools and set the initial and final ports. The initial port needs to be 80 and 443, and the final has to be the initial port, plus the amount of VMs in the autoscale.

2. VHD

Here, the only important step is change the URL to your URI of the VHD, obtained when the VHD was created.

3. Metrics

The memory metrics are set to increase the amount of VMs when the percent of used memory reaches 60, and decrease when it reaches 30. Also, in the timeWindow, you can set the time that autoscale will wait to increase and decrease.

That’s it! Now you just need to save your template and deploy!

Good luck 😉

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.

Software Engineer with experience in analysis and development of systems. Free software enthusiast and apprentice of new tech.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu