Followers

Thursday, 7 December 2023

7.Create and deploy virtual machines in an availability set using Azure CLI

 

Create an availability set

You can create an availability set using az vm availability-set create. In this example, the number of update and fault domains is set to 2 for the availability set named myAvailabilitySet in the myResourceGroupAvailability resource group.

First, create a resource group with az group create, then create the availability set:

Azure CLICopyTry It

az group create --name myResourceGroupAvailability --location eastus az vm availability-set create \ --resource-group myResourceGroupAvailability \ --name myAvailabilitySet \ --platform-fault-domain-count 2 \ --platform-update-domain-count 2

Availability Sets allow you to isolate resources across fault domains and update domains. A fault domain represents an isolated collection of server + network + storage resources. In the preceding example, the availability set is distributed across at least two fault domains when the VMs are deployed. The availability set is also distributed across two update domains. Two update domains ensure that when Azure performs software updates, the VM resources are isolated, preventing all the software that runs on the VM from being updated at the same time.

Create VMs inside an availability set

VMs must be created within the availability set to make sure they are correctly distributed across the hardware. An existing VM cannot be added to an availability set after it is created.

When a VM is created with az vm create, use the --availability-set parameter to specify the name of the availability set.

Azure CLI

for i in `seq 1 2`; do az vm create \ --resource-group myResourceGroupAvailability \ --name myVM$i \ --availability-set myAvailabilitySet \ --size Standard_DS1_v2 \ --vnet-name myVnet \ --subnet mySubnet \ --image UbuntuLTS \ --admin-username azureuser \ --generate-ssh-keys done

There are now two virtual machines within the availability set. Because they are in the same availability set, Azure ensures that the VMs and all their resources (including data disks) are distributed across isolated physical hardware. This distribution helps ensure much higher availability of the overall VM solution.

The availability set distribution can be viewed in the portal by going to Resource Groups > myResourceGroupAvailability > myAvailabilitySet. The VMs are distributed across the two fault and update domains, as shown in the following example:



Check for available VM sizes

Additional VMs can be added to the availability set later, where VM sizes are available on the hardware. Use az vm availability-set list-sizes to list all the available sizes on the hardware cluster for the availability set:

Azure CLI Copy Try It

az vm availability-set list-sizes \ --resource-group myResourceGroupAvailability \ --name myAvailabilitySet \ --output table



No comments:

Post a Comment

12. Creating a Hub and Spoke Network with a DMZ and Allowing Access to Azure Arc and Other Microsoft URLs from the Azure Portal

12. Creating a Hub and Spoke Network with a DMZ and Allowing Access to Azure Arc and Other Microsoft URLs from the Azure Portal. 1. Create a...