0
0
Azurecloud~5 mins

High availability design patterns in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
High availability design patterns help keep your applications running without interruption. They reduce downtime by spreading resources and handling failures automatically.
When you want your website to stay online even if one server fails
When you run a database that must not lose data or stop working
When you deploy an app that needs to serve users from different regions
When you want to balance traffic so no single server gets overloaded
When you need automatic recovery from hardware or software problems
Config File - azure-deploy.json
azure-deploy.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Network/loadBalancers",
      "apiVersion": "2022-05-01",
      "name": "myLoadBalancer",
      "location": "eastus",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "frontendIPConfigurations": [
          {
            "name": "LoadBalancerFrontEnd",
            "properties": {
              "publicIPAddress": {
                "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
              }
            }
          }
        ],
        "backendAddressPools": [
          {
            "name": "myBackendPool"
          }
        ],
        "loadBalancingRules": [
          {
            "name": "httpRule",
            "properties": {
              "frontendIPConfiguration": {
                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', 'myLoadBalancer'), '/frontendIPConfigurations/LoadBalancerFrontEnd')]"
              },
              "backendAddressPool": {
                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', 'myLoadBalancer'), '/backendAddressPools/myBackendPool')]"
              },
              "protocol": "Tcp",
              "frontendPort": 80,
              "backendPort": 80,
              "enableFloatingIP": false,
              "idleTimeoutInMinutes": 4,
              "loadDistribution": "Default",
              "probe": {
                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', 'myLoadBalancer'), '/probes/httpProbe')]"
              }
            }
          }
        ],
        "probes": [
          {
            "name": "httpProbe",
            "properties": {
              "protocol": "Http",
              "port": 80,
              "requestPath": "/",
              "intervalInSeconds": 15,
              "numberOfProbes": 2
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachineScaleSets",
      "apiVersion": "2022-03-01",
      "name": "myVMSS",
      "location": "eastus",
      "sku": {
        "name": "Standard_DS1_v2",
        "tier": "Standard",
        "capacity": 2
      },
      "properties": {
        "overprovision": true,
        "upgradePolicy": {
          "mode": "Manual"
        },
        "virtualMachineProfile": {
          "storageProfile": {
            "imageReference": {
              "publisher": "Canonical",
              "offer": "UbuntuServer",
              "sku": "18.04-LTS",
              "version": "latest"
            }
          },
          "osProfile": {
            "computerNamePrefix": "vmss",
            "adminUsername": "azureuser",
            "adminPassword": "P@ssw0rd1234!"
          },
          "networkProfile": {
            "networkInterfaceConfigurations": [
              {
                "name": "nicConfig",
                "properties": {
                  "primary": true,
                  "ipConfigurations": [
                    {
                      "name": "ipConfig",
                      "properties": {
                        "subnet": {
                          "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
                        },
                        "loadBalancerBackendAddressPools": [
                          {
                            "id": "[concat(resourceId('Microsoft.Network/loadBalancers', 'myLoadBalancer'), '/backendAddressPools/myBackendPool')]"
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ]
}

This Azure Resource Manager template creates a Load Balancer and a Virtual Machine Scale Set (VMSS).

The Load Balancer distributes incoming traffic on port 80 to the VM instances in the scale set, ensuring high availability.

The VMSS automatically manages multiple VM instances, allowing your app to stay online even if one VM fails.

Key sections:

  • loadBalancers: Defines the public IP, frontend IP, backend pool, health probe, and load balancing rules.
  • virtualMachineScaleSets: Defines VM instances with Ubuntu image, admin credentials, network config, and links to the load balancer backend pool.
Commands
Create a resource group to hold all related Azure resources in one place.
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 - Specifies the resource group name
--location - Specifies the Azure region
Deploy the ARM template to create the load balancer and VM scale set for high availability.
Terminal
az deployment group create --resource-group myResourceGroup --template-file azure-deploy.json
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Resources/deployments/deployment1", "name": "deployment1", "properties": { "provisioningState": "Succeeded", "outputs": {} } }
--resource-group - Specifies the target resource group
--template-file - Specifies the ARM template file to deploy
Check the status of VM instances in the scale set to confirm they are running.
Terminal
az vmss list-instances --resource-group myResourceGroup --name myVMSS
Expected OutputExpected
[ { "instanceId": "0", "vmId": "11111111-1111-1111-1111-111111111111", "osName": "Linux", "osVersion": "18.04", "statuses": [ { "code": "PowerState/running", "level": "Info", "displayStatus": "VM running", "time": null } ] }, { "instanceId": "1", "vmId": "22222222-2222-2222-2222-222222222222", "osName": "Linux", "osVersion": "18.04", "statuses": [ { "code": "PowerState/running", "level": "Info", "displayStatus": "VM running", "time": null } ] } ]
--resource-group - Specifies the resource group
--name - Specifies the VM scale set name
Verify the load balancer configuration and ensure it is active and linked to backend VMs.
Terminal
az network lb show --resource-group myResourceGroup --name myLoadBalancer
Expected OutputExpected
{ "name": "myLoadBalancer", "location": "eastus", "sku": { "name": "Standard" }, "properties": { "frontendIPConfigurations": [ { "name": "LoadBalancerFrontEnd", "properties": { "publicIPAddress": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP" } } } ], "backendAddressPools": [ { "name": "myBackendPool" } ], "loadBalancingRules": [ { "name": "httpRule", "properties": { "frontendPort": 80, "backendPort": 80, "protocol": "Tcp" } } ] } }
--resource-group - Specifies the resource group
--name - Specifies the load balancer name
Key Concept

If you remember nothing else from this pattern, remember: spreading your app across multiple servers with a load balancer keeps it running even if one server fails.

Common Mistakes
Not linking the VM scale set to the load balancer backend pool
Traffic won't be distributed to the VM instances, causing downtime or no response.
Ensure the VM scale set network interface configuration includes the load balancer backend address pool.
Using a single VM without redundancy
If that VM fails, your app goes offline with no backup.
Use a VM scale set or multiple VMs behind a load balancer for redundancy.
Skipping health probes in the load balancer
The load balancer can't detect unhealthy VMs and may send traffic to them, causing errors.
Configure health probes to monitor VM health and route traffic only to healthy instances.
Summary
Create a resource group to organize your Azure resources.
Deploy an ARM template that sets up a load balancer and a VM scale set for high availability.
Verify VM instances are running and the load balancer is properly configured to distribute traffic.