Select Page

In the last couple of weeks I have been working with a client that needed to deploy a two-tier web application that would act as a web store and they predicted that on the launch day about 1500-3000 users would hit the store. Now with that amount of client connections hitting one server would have been a complete failure so we needed to set up multiple web servers and configure Azure’s load balancer to balance the incoming traffic to multiple VMs. Now with the theory in place we just needed to find out how many frontend VMs were needed and after analyzing the facts we settled on the magic number of 10 front facing VMs with one beefy VM on the backend.

After having all the details now comes the hard part. How do I NOT deploy that many VMs manually? I chose not to go with the Azure Resource Manager for this project because I’m not yet convinced that ARM is ready for production deployments so ARM templates were off the plate. Now I didn’t have anything that came even remotely close to help me deploy the much needed VMs so I started PowerShell ISE and wrote a simple script that would create the VMs, create the needed endpoints and add a data disk, set the provisioned IP as static and so on. After an two hours or so I finished the script and ran it to see what happens and the result was OK but the script wasn’t modular enough and it served only one specific deployment and that didn’t help me at all in the long run. So after deploying and configuring all the VMs I started working on turning the script into a function that would help me cover more that one scenario.

After writing on paper what I needed from the script, I started working on it and here it is 🙂

Basically the script serves one purpose and that is to deploy a large amount of VMs in a Resource Group that will be set up as web servers. The script can deploy Windows or Linux VMs, all you need is to specify the VM Image of choice what type of VM you’re deploying. While I was developing the script I faced a problem in getting the VM Image name right so I removed that problem from the equation by adding a way to open a grid view that showed all the available VM images by label and pass them to the VMIMage variable. So if the $VMImage variable is not filled then the list comes up and you can choose what you want to deploy.

Vmtype

There are two problems that I couldn’t solve the way I wanted. Due to the way Azure works now by grouping up everything in Resource Groups (which is a very nice feature) and that sooner or later the Azure team will close the old portal (manage.windowsazure.com), if you want everything in one resource group and not deal with the hassle of creating virtual networks in PowerShell, you need to manually create the Resource Group, Virtual Network and Storage Account and the cloud service name be the same as the Resource Group and there’s no way around it.

Now with that out of the way. The best way to use the script is by using a method called splatting, which in short means that you create a hash table with all the parameters filled and pass them as a variable.

Here’s an example:

As you can see from the example above that splatting makes the script be easier to read and manage compared to something like this:

In any way, you can chose what ever method you want in order to use the script.

In closing, the script deploys and configures 10 VMs in about 58 minutes, if you do it manually it can take up to 6 hours which is quite a brain number, believe me, I tried it.

Hope this script solves a problem or two 🙂

The Script:

Pin It on Pinterest