Month: October 2018

Adding VMs to an Availability Set after they are created

Adding VMs to an Availability Set after they are created

Availability Set Tips and Tricks

An Availability set in Azure is a way of logically grouping virtual machines in order to protect them from a Unplanned Hardware Maintenance Event, An Unexpected Downtime, Planned Maintenance events When virtual machines are part of an availability set they are separated across multiple update and fault domains.

Fault domains define the group of virtual machines that share a common power source and network switch.

Update domains indicate groups of virtual machines and underlying physical hardware that can be rebooted at the same time. Microsoft will reboot one update domain at a time with a wait time of 30 minutes before the next update domain is restarted.

However in order to add a machine to an an availability set it must be added at the time of creation. Now this is easily overseen and you could end up in a position where you have installed your required applications and configurations and not added your new VM to an availability set. So does this mean you have to start from scratch?

Well…No is the answer, remember the configurations you made are applied to the OS/DATA disks and not he VM itself. What we can do in this scenario is redeploy the VM using the same OS/DATA disks and add it to the required Availability Set.

In order to do this we will need to install the Availability Set PowerShell Module from GitHub. Run the below command to complete this:

Install-Module AzureRm.AvailabilitySetManagement

Once you have installed the module we will now run the below command changing the parameters to your required environment:

Add-AzureRmAvSetVmToAvailabilitySet -ResourceGroupName "MyResourceGroup" -VMName "KAM-VM1" -OsType windows -AvailabilitySet "myAvailabilitySet"

This will now delete your VM (your VM OS/data disks will remain intact). Your VM will be re-created with the original OS/DATA disks attached. This is accomplished by creating an ARM template with the current configurations and redeploying your VM via a new ARM template, this time with the availability set.

Important to note:

  1. Any VM extensions will not be re-created and will therefore need to be added on manually.
  2. Accelerated Networking must be in a disabled state

That’s all for now folks, let me know how you get on in the comments below!

Learn more about Availability Sets here