Creating VMs inside an availability set

You can't add an existing virtual machine to an availability set once the virtual machine has been created. Virtual machines must be created within an availability set at the time of deployment to ensure that they are properly distributed across the backend hardware.

The hardware in a location is divided into multiple update domains and fault domains. An update domain is a group of VMs and underlying physical hardware that can be rebooted at the same time. Whereas VMs in the same fault domain share common storage as well as a common power source and network switch.

When you create a virtual machine with the New-AzureRmVM command, the AvailabilitySetName switch is used to specify the availability set into which the virtual machine should be deployed.

Deploying a new virtual machine into an availability set is virtually identical to deploying a virtual machine without an availability set. The only difference is the addition of the switch mentioned before.

Before deploying any new virtual machines, you need to set an administrator username and password for the VMs by running the Get-Credential command, as follows:

$cred = Get-Credential

With a local admin credential created, create two new virtual machines in myAvailabilitySet. Run the following command twice to create two separate VMs, specifying myVM1 and myPublicIP1 for the first virtual machine and myVM2 and myPublicIP2 for the second one. All other switch values should remain the same:

New-AzureRmVm `
-ResourceGroupName "VMLab" `
-Name "myVM1" `
-Location "EastUS" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNSG" `
-PublicIpAddressName "myPublicIP1" `
-AvailabilitySetName "myAvailabilitySet" `
-Credential $cred `
-AsJob

The -AsJob parameter creates the virtual machines as background tasks, so control of the PowerShell prompt returns to you. It takes a few minutes to create and configure both virtual machines but, when finished, you have two virtual machines distributed across the underlying hardware.

You can type Get-AzureRmVm at the PowerShell prompt to see the status of your VM deployments. The command should look like that in the following screenshot:

You can confirm that both machines have been added to the availability set by running the Get-AzureRmAvailabilitySet command as follows:

Get-AzureRmAvailabilitySet `
-ResourceGroupName "VMLab" `
-Name "MyAvailabilitySet"

Running the preceding command should return the following feedback:

If you've done everything correctly, you should see a screen like the previous screenshot. It should have both myVM1 and myVM2 listed in the availability set.

Congratulations! You have now learned how to create an availability set and how to create virtual machines within one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.127.197