0
0
Azurecloud~5 mins

Backend pools and health probes in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run an app on multiple servers, you need a way to send user requests to healthy servers only. Backend pools group these servers, and health probes check if each server is working well. This keeps your app reliable and fast.
When you want to balance user traffic across several servers to avoid overload.
When you need to automatically stop sending requests to servers that are down or slow.
When you want to improve app availability by detecting and bypassing unhealthy servers.
When you deploy a web app behind an Azure Load Balancer or Application Gateway.
When you want to monitor server health without manual checks.
Config File - backendpool-healthprobe.json
backendpool-healthprobe.json
{
  "type": "Microsoft.Network/applicationGateways",
  "apiVersion": "2023-02-01",
  "name": "myAppGateway",
  "location": "eastus",
  "properties": {
    "backendAddressPools": [
      {
        "name": "myBackendPool",
        "properties": {
          "backendAddresses": [
            { "ipAddress": "10.0.1.4" },
            { "ipAddress": "10.0.1.5" }
          ]
        }
      }
    ],
    "probes": [
      {
        "name": "myHealthProbe",
        "properties": {
          "protocol": "Http",
          "host": "localhost",
          "path": "/health",
          "interval": 15,
          "timeout": 5,
          "unhealthyThreshold": 3,
          "match": {
            "statusCodes": ["200-399"]
          }
        }
      }
    ],
    "httpListeners": [
      {
        "name": "myListener",
        "properties": {
          "frontendIPConfiguration": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/frontendIPConfigurations/myFrontendIP" },
          "frontendPort": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/frontendPorts/myFrontendPort" },
          "protocol": "Http"
        }
      }
    ],
    "requestRoutingRules": [
      {
        "name": "rule1",
        "properties": {
          "ruleType": "Basic",
          "httpListener": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/httpListeners/myListener" },
          "backendAddressPool": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/backendAddressPools/myBackendPool" },
          "backendHttpSettings": {
            "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/backendHttpSettingsCollection/myBackendHttpSettings"
          }
        }
      }
    ],
    "backendHttpSettingsCollection": [
      {
        "name": "myBackendHttpSettings",
        "properties": {
          "port": 80,
          "protocol": "Http",
          "probe": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/probes/myHealthProbe" }
        }
      }
    ]
  }
}

This JSON defines an Azure Application Gateway with:

  • backendAddressPools: Groups two servers by their IPs to receive traffic.
  • probes: A health probe that checks the path '/health' on each server every 15 seconds.
  • httpListeners: Listens for incoming HTTP requests.
  • requestRoutingRules: Routes requests from the listener to the backend pool using the health probe.
  • backendHttpSettingsCollection: Connects the health probe to the backend pool on port 80.

This setup ensures traffic only goes to healthy servers.

Commands
This command creates an Azure Application Gateway named 'myAppGateway' with a backend pool of two servers and a health probe checking '/health' every 15 seconds. It sets up the frontend and backend ports and protocols.
Terminal
az network application-gateway create --name myAppGateway --resource-group myResourceGroup --location eastus --sku Standard_v2 --capacity 2 --frontend-port 80 --http-settings-port 80 --http-settings-protocol Http --probe-name myHealthProbe --probe-path /health --probe-interval 15 --probe-timeout 5 --probe-unhealthy-threshold 3 --backend-pool-name myBackendPool --backend-addresses 10.0.1.4 10.0.1.5
Expected OutputExpected
{ "provisioningState": "Succeeded", "resourceGroup": "myResourceGroup", "name": "myAppGateway", "location": "eastus", "sku": { "name": "Standard_v2", "tier": "Standard_v2" }, "capacity": 2 }
--probe-path - Sets the URL path the health probe checks
--backend-addresses - Specifies the IP addresses in the backend pool
--probe-unhealthy-threshold - Number of failed probes before marking backend as unhealthy
This command shows the current configuration of the Application Gateway to verify the backend pool and health probe are set correctly.
Terminal
az network application-gateway show --name myAppGateway --resource-group myResourceGroup
Expected OutputExpected
{ "name": "myAppGateway", "resourceGroup": "myResourceGroup", "location": "eastus", "provisioningState": "Succeeded", "backendAddressPools": [ { "name": "myBackendPool", "backendAddresses": [ { "ipAddress": "10.0.1.4" }, { "ipAddress": "10.0.1.5" } ] } ], "probes": [ { "name": "myHealthProbe", "properties": { "protocol": "Http", "path": "/health", "interval": 15 } } ] }
This command checks the health status of each server in the backend pool using the configured health probe.
Terminal
az network application-gateway backend-health show --name myAppGateway --resource-group myResourceGroup
Expected OutputExpected
{ "backendAddressPools": [ { "name": "myBackendPool", "backendHttpSettingsCollection": [ { "servers": [ { "address": "10.0.1.4", "health": "Healthy" }, { "address": "10.0.1.5", "health": "Healthy" } ] } ] } ] }
Key Concept

If you remember nothing else from this pattern, remember: backend pools group your servers and health probes check their status to send traffic only to healthy ones.

Common Mistakes
Not configuring the health probe path correctly or leaving it empty.
The probe won't correctly check server health, causing traffic to be sent to unhealthy servers.
Set the probe path to a valid URL on your servers that returns a success status when healthy, like '/health'.
Forgetting to add backend server IPs to the backend pool.
No servers receive traffic, so your app won't respond to users.
Always specify the IP addresses or FQDNs of your backend servers in the backend pool configuration.
Setting the unhealthy threshold too low, causing servers to be marked unhealthy too quickly.
Temporary glitches can cause servers to be wrongly marked unhealthy, reducing availability.
Use a reasonable threshold like 3 failed probes before marking a server unhealthy.
Summary
Create an Application Gateway with backend pools grouping your servers.
Configure health probes to check server health regularly on a specific path.
Use commands to verify the gateway configuration and backend server health.