0
0
Azurecloud~5 mins

Availability sets for redundancy in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run apps on cloud servers, sometimes a server can fail or need maintenance. Availability sets help keep your app running by spreading your servers across different groups so not all fail at once.
When you want to keep your website running even if one server has a problem.
When you deploy multiple virtual machines that need to stay available during updates.
When you want to avoid downtime caused by hardware failures in the cloud.
When you need to meet a service level agreement that requires high uptime.
When you want to balance your app's servers across different physical racks in the data center.
Config File - availability-set.json
availability-set.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Compute/availabilitySets",
      "apiVersion": "2022-03-01",
      "name": "myAvailabilitySet",
      "location": "eastus",
      "properties": {
        "platformFaultDomainCount": 2,
        "platformUpdateDomainCount": 5
      },
      "sku": {
        "name": "Aligned"
      }
    }
  ]
}

This JSON file is an Azure Resource Manager (ARM) template that creates an availability set named myAvailabilitySet in the eastus region.

platformFaultDomainCount sets how many separate physical racks your servers will be spread across to avoid hardware failures affecting all at once.

platformUpdateDomainCount sets how many groups your servers are divided into for updates, so not all update at the same time.

The sku with value Aligned means it uses the latest Azure infrastructure for availability sets.

Commands
Create a resource group to hold your availability set and other resources. This groups them together for easy management.
Terminal
az group create --name myResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup", "location": "eastus", "managedBy": null, "name": "myResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group.
--location - Specifies the Azure region for the resource group.
Deploy the availability set using the ARM template file you created. This sets up the redundancy groups in Azure.
Terminal
az deployment group create --resource-group myResourceGroup --template-file availability-set.json
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Resources/deployments/deployment1", "name": "deployment1", "properties": { "provisioningState": "Succeeded", "outputs": {} }, "resourceGroup": "myResourceGroup", "timestamp": "2024-06-01T12:00:00Z", "templateLink": null, "mode": "Incremental" }
--resource-group - Specifies the resource group where the deployment happens.
--template-file - Points to the ARM template file to deploy.
Create a virtual machine named myVM1 inside the availability set to ensure it benefits from redundancy.
Terminal
az vm create --resource-group myResourceGroup --name myVM1 --image UbuntuLTS --availability-set myAvailabilitySet --admin-username azureuser --generate-ssh-keys
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM1", "location": "eastus", "name": "myVM1", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "52.170.12.34", "resourceGroup": "myResourceGroup", "zones": null }
--availability-set - Assigns the VM to the availability set for redundancy.
--generate-ssh-keys - Automatically creates SSH keys for secure login.
List all virtual machines in the resource group with details to verify the VM is created and part of the availability set.
Terminal
az vm list --resource-group myResourceGroup --show-details --output table
Expected OutputExpected
Name ResourceGroup Location Zones PowerState PublicIps PrivateIps ------ --------------- ---------- ------- ------------ ----------- ----------- myVM1 myResourceGroup eastus VM running 52.170.12.34 10.0.0.4
--show-details - Shows extra info like power state and IP addresses.
--output - Formats the output as a readable table.
Key Concept

If you remember nothing else from this pattern, remember: availability sets keep your app running by spreading servers across different physical and update groups to avoid single points of failure.

Common Mistakes
Creating virtual machines without assigning them to the availability set.
The VMs won't be protected by the availability set, so they can all fail or update at the same time.
Always use the --availability-set flag when creating VMs to include them in the availability set.
Setting platformFaultDomainCount or platformUpdateDomainCount to 1.
This means no real spreading across racks or update groups, so redundancy is lost.
Use at least 2 fault domains and multiple update domains for proper redundancy.
Summary
Create a resource group to organize your cloud resources.
Deploy an availability set using an ARM template to define fault and update domains.
Create virtual machines inside the availability set to ensure redundancy.
Verify the VMs are running and part of the availability set with Azure CLI commands.