Earlier this month I posted an article about using PowerShell to automate the deployment of Azure ARM VMs.  In this article I expand on that by exploring and automating the deployment of Azure RM Virtual Machine Availability Sets.

Availability Set

In Azure and similar public clouds, a Virtual Machine is subject to planned and unplanned outages that may make the VM not available. The hypervisor on top of which a VM lives needs periodical patching and such. Other infrastructure in the Azure Stamp may need hardware, firmware, or software patching or update that may require shutting down the VM.

Fault domains and Update domains

Microsoft defines Update domains and Fault domains in Azure. All resources in the same update domain are subject to simultaneous down time. Resources in the same Fault domain share infrastructure elements such as power and networking that render them susceptible to simultaneous unplanned failure. VMs in an availability set are distributed across different Fault and Upgrade domains. This ensures that in case of planned upgrades and unplanned outages, one of the VMs in the Availability Set remains up.

To qualify for the VM’s 99.95% uptime SLA, VMs must be deployed in an Availability Set (2 VMs minimum)

Automating the task of deploying Azure VMs in Availability Set

This PowerShell Script has been updated (version 2).  It can be used to deploy several ARM VMs in Availability Set. Existing VMs can be added to new or existing Availability Set. A VM must be shutdown to be added to Availability Set.

Here’s an example of using the script:

# Login to Azure subscription
# Login-AzureRmAccount

$ResourceGroup = 'VMGroup17' # To be created if not exist
$Location = 'eastus' # Get-AzureRmLocation | sort Location | Select Location
$AvailabilitySetName = 'Availability17' # To be created if not exist, must be in the same 'location'
$VMProps = @{
 SubscriptionName = 'Sam Test 1' # Name of existing Azure subscription
 Location = $Location 
 ResourceGroup = $ResourceGroup 
 AvailabilitySetName = $AvailabilitySetName 
 ConfirmShutdown = $true # If adding existing VMs to Availaibility set, the script must shut down the VMs
 StorageAccountPrefix = $ResourceGroup # To be created if not exist, only lower case letters and numbers, must be Azure unique 
 AdminName = 'myAdmin17' # This will be the new VM(s) local administrator 
 VMName = ('vm01','vm02','vm03','vm04','vm05','vm06','vm07','vm08','vm09') # Name(s) of VM(s) to be created.
 VMSize = 'Standard_A1_v2' # (Get-AzureRoleSize).RoleSizeLabel to see available sizes in this Azure location 
 vNetName = 'Seventeen' # This will be the name of the virtual network to be created/updated if exist
 vNetPrefix = '10.17.0.0/16' # To be created/updated
 SubnetName = 'vmSubnet' # This will be the name of the subnet to be created/updated
 SubnetPrefix = '10.17.0.0/24' # Must be subset of vNetPrefix above - to be created/updated
}

# Using version 2 of the Deploy-AzureARMVM.ps1 from https://gallery.technet.microsoft.com/Powershell-script-to-2e95d2df
.\Deploy-AzureARMVM.ps1 @VMProps

ARMVM01

Here I use the script to deploy 9 Azure ARM VMs in Availability Set. The final part of the output looks like:

ARMVM02

Notice that the number of Fault domains is 3 identified as 0, 1, 2. The number of Update domains is 5 identified as 0, 1, 2, 3, 4.

When a VM is added to an Availability Set, the choice/assignment of which Fault domain and Upgrade domain is automatic.

For more information on using Azure ARM VMs to achieve VM High Availability and Fault Tolerance, , contact the Exigent Azure Consulting team.