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
- Frontend IP Configuration
- Backend Address Pools
- Health Probes
- Load Balancing Rules
- 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
- Protocol
- Port
- intervalInSeconds (amount of time between probe attempts)
- numberOfProbes (Unhealthy Threshold)
- 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
- Frontend IP Configuration
- Backend Address Pool
- Probe (Health Probe)
- Protocol
- Frontend Port
- Backend Port
- idleTimeoutInMinutes (keep a TCP or HTTP connection open without relying on clients)
- 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!