New Delhi , Moti Nagar
+91-9007641046
subhendu@subhendumct.com

Removing VM from Availability Set ?? – It’s possible , BUT !!!

Live in Future - Live in Cloud

Removing VM from Availability Set ?? – It’s possible , BUT !!!

Greetings !!

 

During class I talk abut VM and application availability . availability set and availability  zone is best way to provide maximum availability  to our infrastructure . As we know we can’t configure HA after the VM creation . Recommendation is create the availability set first then create VM and select that exiting av set .

FAQ :

Q1: Can we select/create an AV set with all vm’s just keeping future possibilities in mind ?

Ans : No . You should not create or attached AV set unless you have 2 VM for the same application . If you have single VM in AV set then it’s a problem . You will not get outage notification from Microsoft .

Q2 . Do I need to delete all VM resource and create a new one ?

Ans : No , use this script . You will save your time and effort .

So if you have single VM in availability set remove that VM from av set and deploy the VM as a new one . But it’s a long task . Let me make your life a bit easy .

This entire work is decided into 3 part . First preparation – then VM provisioning – Post VM configuration .

Finally the Migration Day :

** Please make sure you have proper ticket and right authorization to perform this task . Make sure you have informed application and change management team and you have outage window . Now , Grab a good cup of coffee and enjoy the work .

  1. First of all we have to create a server book that contain each and every details of all IIS server . This server book is specifically for post deployment configuration cross-checking .
  2. Open Azure portal and Stop backup of Virtual Machine .
  3. Then  Stop the Virtual Machine .
  4. Now go to Disk Section and Click on OS Disk .
  5. Create snapshot of OS and DATA disk . (In case anything goes wrong)
  6. Open powershell with admin right and install required modules and then login to Azure .
    #Set-ExecutionPolicy Unrestricted
    
    #Install-Module AzureRM
    
    #import-module AzureRM
    
    ##Login into protal
    
    #Connect-AzureRmAccount
  7. Run this script to re-create VM . Change VM name and resource group name before run this script. Mentioned VM will be deleted and re-create again.
## Please replace the highlighted part

# Set variables (Will be use in entire script)

$resourceGroup = "Provide VM RG name"

$vmName = "KingWindowsVM"


# Get the details of the VM to be moved to the Availability Set

$originalVM = Get-AzureRmVM `

-ResourceGroupName $resourceGroup `

-Name $vmName

# This command will remove the original VM

Remove-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName


# Remove Availability set information

$originalVM.AvailabilitySetReference = $null

# Create the basic configuration for the replacement VM

$newVM = New-AzureRmVMConfig `

-VMName $originalVM.Name `

-VMSize $originalVM.HardwareProfile.VmSize `


Set-AzureRmVMOSDisk `

-VM $newVM -CreateOption Attach `

-ManagedDiskId $originalVM.StorageProfile.OsDisk.ManagedDisk.Id `

-Name $originalVM.StorageProfile.OsDisk.Name `

-Windows


# Add Data Disks

foreach ($disk in $originalVM.StorageProfile.DataDisks) {

Add-AzureRmVMDataDisk -VM $newVM `

-Name $disk.Name `

-ManagedDiskId $disk.ManagedDisk.Id `

-Caching $disk.Caching `

-Lun $disk.Lun `

-DiskSizeInGB $disk.DiskSizeGB `

-CreateOption Attach

}

# Add NIC(s) and keep the same NIC as primary

foreach ($nic in $originalVM.NetworkProfile.NetworkInterfaces) {

if ($nic.Primary -eq "True")

{

Add-AzureRmVMNetworkInterface `

-VM $newVM `

-Id $nic.Id -Primary

}

else

{

Add-AzureRmVMNetworkInterface `

-VM $newVM `

-Id $nic.Id

}

}

# Recreate the VM

New-AzureRmVM `

-ResourceGroupName $resourceGroup `

-Location $originalVM.Location `

-VM $newVM `

-DisableBginfoExtension


8. Once you have VM in place open old VM config and setup following things :

  • Setup OS diagnostics .
  • Setup boot diagnostics .
  • setup alert .
  • Re-Setup the backup or DR .

Amazing man , you have saved your organization’s VM from and unexpected outage . Congrats .

 

Leave a Reply

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