Load Balancer Template with multiple Health probes and Load Balancing rules


This template allows you to create an internal load balancer with multiple Health probes and Load balancing rules. Same logic can be applied to Inbound NAT rules if you wish to create them as well in Load Balancer.

To read more about Azure Load Balancer, refer this article

Below is a snapshot from JSON Outline window

Load Balancer mainly has below properties

  1. Frontend IP Configuration
  2. Backend Address Pools
  3. Health Probes
  4. Load Balancing Rules
  5. Inbound NAT rules (not covered in this post)

Health probes and Load Balancing rules are created under copy section as we need to create them based on the parameter array. To read more about copy function, read this article.

Below is expanded copy section for Health Probes. Note that the name of the section should be ‘probe’. This template defines below properties of a Health Probe

  1. Protocol
  2. Port
  3. intervalInSeconds (amount of time between probe attempts)
  4. numberOfProbes (Unhealthy Threshold)
  5. requestPath (the uri used for requesting health status from the backend endpoint)

Below is expanded copy section for Load Balancing rules. Note that the name of the section should be ‘loadBalancingRules’. This template defines below properties of a Load Balancing rule

  1. Frontend IP Configuration
  2. Backend Address Pool
  3. Probe (Health Probe)
  4. Protocol
  5. Frontend Port
  6. Backend Port
  7. idleTimeoutInMinutes (keep a TCP or HTTP connection open without relying on clients)
  8. enableFloatingIP (It can be enabled only if port and Backend port matches)

Below is the full template

{

“$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,

“contentVersion”: “1.0.0.0”,

“parameters”: {

“loadBalancerName”: {

 “type”: “string”

},

“subscriptionId”: {

“type”: “string”

},

“virtualNetworkName”: {

“type”: “string”

},

“subnetName”: {

“type”: “string”

},

“location”: {

“type”: “string”

},

“lbFrontendIPPoolName”: {

“type”: “string”,

“defaultValue”: “LoadBalancerFrontEnd”

},

“lbBackendPoolName”: {

“type”: “string”,

“defaultValue”: “LoadBalancerBackEnd”

},

“healthProbes”: {

“type”: “array”,

“defaultValue”: [

{

“name”: “HealthProbe-TCP-80”,

“protocol”: “TCP”,

“port”: “80”,

“intervalInSeconds”: “15”,

“numberOfProbes”: “2”,

“requestPath”: null

},

{

“name”: “HealthProbe-TCP-443”,

“protocol”: “TCP”,

“port”: “443”,

“intervalInSeconds”: “15”,

“numberOfProbes”: “2”,

“requestPath”: null

},

{

“name”: “HealthProbe-HTTP-443”,

“protocol”: “HTTP”,

“port”: “443”,

“intervalInSeconds”: “15”,

“numberOfProbes”: “2”,

“requestPath”: “TestPath”

}

]

},

“lbRules”: {

“type”: “array”,

“defaultValue”: [

{

“name”: “HTTP”,

“lbFrontendIPPoolName”: “LoadBalancerFrontEnd”,

“lbBackendPoolName”: “LoadBalancerBackEnd”,

“healthProbe”: “HealthProbe-TCP-80”,

“protocol”: “TCP”,

“frontendPort”: “80”,

“backendPort”: “80”,

“idleTimeoutInMinutes”: “15”,

“enableFloatingIP”: false

},

{

“name”: “HTTPS”,

“lbFrontendIPPoolName”: “LoadBalancerFrontEnd”,

“lbBackendPoolName”: “LoadBalancerBackEnd”,

“healthProbe”: “HealthProbe-TCP-443”,

“protocol”: “TCP”,

“frontendPort”: “443”,

“backendPort”: “443”,

“idleTimeoutInMinutes”: “15”,

“enableFloatingIP”: false

}

]

}

},

“variables”: {

“vnetID”: “[resourceId(‘Microsoft.Network/virtualNetworks’, parameters(‘virtualNetworkName’))]”,

“subnetRef”: “[concat(variables(‘vnetID’),’/subnets/’,variables(‘subnetName’))]”,

“lbID”: “[resourceId(‘Microsoft.Network/loadBalancers’, parameters(‘loadBalancerName’))]”

},

“resources”: [

{

“apiVersion”: “2017-03-01”,

“name”: “[parameters(‘loadBalancerName’)]”,

“type”: “Microsoft.Network/loadBalancers”,

“location”: “[parameters(‘location’)]”,

“properties”: {

“frontendIPConfigurations”: [

{

“name”: “[parameters(‘lbFrontendIPPoolName’)]”,

“properties”: {

“subnet”: {

“id”: “[variables(‘subnetRef’)]”

}

}

}

],

“backendAddressPools”: [

{

“name”: “[parameters(‘lbBackendPoolName’)]”

}

],

“copy”: [

{

“name”: “probes”,

“count”: “[length(parameters(‘healthProbes’))]”,

“input”: {

“name”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].name]”,

“properties”: {

“protocol”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].protocol]”,

“port”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].port]”,

“intervalInSeconds”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].intervalInSeconds]”,

“numberOfProbes”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].numberOfProbes]”,

“requestPath”: “[parameters(‘healthProbes’)[copyIndex(‘probes’)].requestPath]”

}

}

},

{

“name”: “loadBalancingRules”,

“count”: “[length(parameters(‘lbRules’))]”,

“input”: {

“name”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].name]”,

“properties”: {

“frontendIPConfiguration”: {

“id”: “[concat(resourceId(‘Microsoft.Network/loadBalancers’, parameters(‘loadBalancerName’)), ‘/frontendIpConfigurations/’,parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].lbFrontendIPPoolName)]”

},

“backendAddressPool”: {

“id”: “[concat(resourceId(‘Microsoft.Network/loadBalancers’, parameters(‘loadBalancerName’)), ‘/backendAddressPools/’,parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].lbBackendPoolName)]”

},

“probe”: {

“id”: “[concat(resourceId(‘Microsoft.Network/loadBalancers’, parameters(‘loadBalancerName’)), ‘/probes/’,parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].healthProbe)]”

},

“protocol”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].protocol]”,

“frontendPort”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].frontendPort]”,

“backendPort”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].backendPort]”,

“idleTimeoutInMinutes”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].idleTimeoutInMinutes]”,

“enableFloatingIP”: “[parameters(‘lbRules’)[copyIndex(‘loadBalancingRules’)].enableFloatingIP]”

}

}

}

]

}

}

],

“outputs”: {

“LB”: {

“type”: “object”,

“value”: “[reference(concat(‘Microsoft.Network/loadBalancers/’, parameters(‘loadBalancerName’)))]”

}

}

}

 

Hope this was helpful. Happy Coding!


Comments (0)

Skip to main content