Azure – Automatically scale out to 1000 of VMs (oh and automatically scale in as well)

So how do you scale your VMs and deploy your app to them automatically?

Enter Virtual Machine Scale Sets (VMSS). Microsoft introduced them not too long ago and they offer the solution to the scaling problem.

Virtual machine scale sets are an Azure compute resource that you can use to deploy and manage a set of identical VMs. With all VMs configured the same, scale sets are designed to support true autoscale, and no pre-provisioning of VMs is required. So it’s easier to build large-scale services that target big compute, big data, and containerized workloads.

So you might think that’s great, I set up a VM, I add it to a scale set and then I can fire up multiple VMs and they will automatically replicate from a “master”. Erm… No… But that would be a great thing for Microsoft to implement in the future.

A Scale set consists of: The VMs, Public IP address, Load Balancer and Storage Account. When a new VM is fired up it will be just a VM with Windows Server – nothing else. The Load Balancer will check which ones are healthy and will route traffic to them. Make sure your load balancer probes for health a http page and not port as if you check for port 80 the server will be up but the web pages content will not be there.

So how do we get our application data to the servers? The process to get them there the first time,when a new server is fired up due to scale up, or when we update our application is the same.

The answer for that is Octopus Deploy and Desired State Configuration (DSC). Also throwing in a VM template or Terraform will make things even easier to create the scale set and your resource group.

So I started by installing an Octopus Deploy server on Azure (you can get it from the Azure Marketplace) and configured a trigger to autodeploy my application to any agents (Octopus Tentacles) that register with it. I thenĀ  created my scale set from an Octopus DSC and IIS DSC, Azure Template that I modified. Good thing with Octopus Deploy is that you can deploy services and applications as well – not only IIS pages.

I created my first process to double check that IIS is enabled and that Default Web Site that binds to port 80 is deleted (as Octopus Deploy, deployed site was going to bind to port 80 as well):

So with Powershell I added my first step to fulfill the requirements above:

Install-WindowsFeature -Name Web-Server -IncludeAllSubFeature -IncludeManagementTools

if (get-website | where-object { $_.name -eq 'Default Web Site' }) {Remove-WebSite -Name "Default Web Site" -ErrorAction Ignore}

The next step is to deploy the IIS application and install the web site that Octopus Deploy does this automatically from my Package.

So here are my VMs getting powered up:

And here is Octopus Deploy without any tentacles (clients) registered with it:

After a while the first instance is up and running:

and shows up in Octopus Deploy:

Immediately the two step installation starts:

After a while the second VM shows up:

In Octopus as well:

And here are the results:

Going to my test website and hitting my url I get my picture back:

So now deployment is complete.

If I want I can go back to Octopus Deploy, upload a new version and send it out to my scale set. Also as a developer you can automate also the process in a CI/CD pipeline, feeding Octopus Deploy from TFS, VSTS, Bamboo, TeamCity or Jenkins, etc. See getting started for more info.

So let’s play a little bit more with that.

I go into Azure Portal and change the Instances to 3:

After a while I have the 3rd instance up and running:

Octopus Deploy has picked it up and is installing the software:

So now we have 3 instances on our Scale Set and all 3 connected to our Octopus Deploy server:

Let’s go and scale it (scale in) back to 2:

Depending on the policy you have set, the VM will be cleaned up from Octopus Deploy as well. We don’t have to scale up to 500 VMs and then back to 20 VMs for example and go into Octopus Deploy console and see those VMs as “offline”. So we can clean up our environment with a policy.

Oh by the way. The idea is not to manually scale it but enable autoscale as you can see in the screenshot:

By default the limit is 100 but you can increase it to 1000.

Also with Octopus Deploy you can manage different enviroments (Production, Testing) with different targets. Everything is easily configurable as you start playing with it. Read key concepts for more.

Have fun!

One thought on “Azure – Automatically scale out to 1000 of VMs (oh and automatically scale in as well)

Leave a Reply

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