Last Update: Sep 04, 2024 | Published: May 10, 2017
In this post, I will explain the benefits of using Azure Managed Disks with availability sets. I will also show how to convert virtual machines in an availability set with unmanaged disks to Managed Disks. These will respect the protection offered by the availability set.
Azure uses availability sets for virtual machines in a few ways:
Availability sets sound like they give us ample protection but there was still a remaining single point of failure. The storage of the virtual machine disks was this point. It was possible for the virtual hard disks of virtual machines to be placed into a single Azure storage cluster. This cluster provides triple-redundancy of storage (LRS) to protect you against disk or JBOD (a tray of just-a-bunch-of-disks) failure and/or maintenance. It does not protect you against a certain outage profile. For example, a virtual machine availability set protects you against a localized outage within a fault domain. A similar style of outage in the Azure storage cluster could bring down all 3 copies of your virtual machines’ disks.
Managed Disks for virtual machines offer many benefits. This is quickly summarized as, “Azure just takes care of all the disk placement for you.” One of those benefits is that if you use Managed Disks with virtual machines in an availability set, then Azure will disperse the disks of the machines across different storage clusters within the data center. If one of the storage clusters fails, then the other copies of your disks remain online. Your service also remains online.
It is possible to convert an availability set of virtual machines from unmanaged disks to Azure Managed Disks. The process understands that you require the service in the availability set to remain online throughout the upgrade process. The upgrade is done one virtual machine at a time. I have added a sleep command after each upgrade. This will occur before the next upgrade starts to add a buffer. Alternatively, you can request manual confirmation that the process should continue after each virtual machine upgrades. This would allow you to check that the last virtual machine is OK before allowing the upgrade to take place for the next machine in the availability set.
The conversion process is done using PowerShell. Note that you should have the latest version of the PowerShell modules. At the time of writing (February 2017), you also need to have the very latest ARM Compute module but this will probably be folded into later bundled installations:
Install-Module AzureRM.Compute -RequiredVersion 2.6.0 -AllowClobber
The PowerShell script for doping the conversion of virtual machines in an availability set is shared below:
CLS $ResourceGroupName = "rg-petri" $AVSetName = "as-petri" $SubscriptionID = "1a2b3c45-aa12-1a23-12a3-a1bcdefg345h" $Delay = 60 Login-AzureRmAccount Select-AzureRmSubscription -SubscriptionId $SubscriptionID Write-Host "`nRetrieving the availability set, $AVSetName" $AVSet = Get-AzureRmAvailabilitySet -ResourceGroupName $ResourceGroupName -Name $avSetName Update-AzureRmAvailabilitySet -AvailabilitySet $AVSet -Managed foreach($VMInstance in $ AVSet.VirtualMachinesReferences) { $VM = Get-AzureRmVM -ResourceGroupName $ResourceGroupName | Where-Object {$_.Id -eq $VMInstance.id} $VMName = $VM.Name Write-Host "`nWorking on the virtual machine, $VMName" Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName -Force Write-Host "`nConverting the disks of virtual machine, $VMName, and then starting it" ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $ResourceGroupName -VMName $VMName Write-Host "`nSleeping for $Delay seconds before proceeding" Sleep $Delay #You can replace the previous two lines with the following to allow for a manual verification before proceeding #Read-Host "Press Enter/Return to continue to the next virtual machine" }
A few variables define the environment that will be upgraded:
The first part of the script will request you to log into your Azure administrator account and then it will select the subscription that you defined in the SubscriptionID variable.
The AVSetName variable is used to retrieve the availability set resource and then the availability set is upgraded to a managed state. This supports the concept of Managed Disks. It instructs Azure to spread Managed Disks in the availability set across different storage clusters.
A for loop will then run and perform an upgrade on each virtual machine in the availability set. This will happen one at a time:
Note that I added a line, commented out using #, that you can use instead of the Sleep cmdlet. Doing this would replace the timed delay with a manual control, which stops the script from running until you press enter. You can use this approach if you want to manually check a converted virtual machine before continuing.