Azure Load Balancer
Azure Load Balancer is a Layer 4 (TCP/UDP) load balancer that enables you to distribute network traffic across multiple virtual machines or cloud services. It provides high availability and improves application responsiveness by routing traffic to healthy instances. Azure Load Balancer is a fully managed service, offering scalability, resilience, and low latency.
Key Features and Benefits
- High Availability: Ensures your applications remain available by automatically detecting and redirecting traffic away from unhealthy instances.
- Scalability: Handles fluctuating traffic loads by distributing requests across a growing pool of resources.
- Performance: Offers low latency and high throughput for your network traffic.
- Layer 4 Load Balancing: Operates at the network layer, making decisions based on IP address and port.
- Load Balancing Rules: Define how traffic is distributed to backend pools based on protocol, port, and IP address.
- Health Probes: Continuously monitors the health of backend instances to ensure traffic is only sent to healthy resources.
- Outbound Connectivity: Supports outbound connections from your virtual machines to the internet.
- Skus: Available in Standard and Basic SKUs, offering different feature sets and capabilities.
How Azure Load Balancer Works
Azure Load Balancer operates in front of your virtual machines or cloud services. When a client sends a request to the load balancer's public or internal IP address, the load balancer uses configured load balancing rules to decide which backend instance should receive the request. Health probes are crucial; they periodically send requests to backend instances. If an instance fails to respond, it's marked as unhealthy, and the load balancer stops sending traffic to it until it becomes healthy again.
Common Use Cases
- Web Application High Availability: Distribute incoming web traffic across multiple web servers.
- Database Load Balancing: Distribute read-only traffic to a farm of database replicas.
- Backend Service Distribution: Load balance traffic to internal microservices.
- Disaster Recovery: Distribute traffic across geographically dispersed regions.
Configuring Azure Load Balancer
Configuration typically involves the following steps:
- Create a Load Balancer: Choose between Standard or Basic SKU, and public or internal type.
- Configure a Backend Pool: Associate the load balancer with the virtual machines or scale sets that will receive traffic.
- Define Health Probes: Specify the protocol, port, and interval for checking the health of backend instances.
- Create Load Balancing Rules: Map frontend IP addresses and ports to backend pools and ports.
- Configure NAT Rules (Optional): For inbound direct server return scenarios.
Important Note:
The Standard SKU of Azure Load Balancer offers more advanced features, including Availability Zones support, better diagnostics, and session persistence. The Basic SKU is suitable for simpler scenarios and cost-effectiveness.
Example Configuration Snippet (ARM Template)
Here's a simplified example of an ARM template snippet for creating a Standard Load Balancer:
{
"type": "Microsoft.Network/loadBalancers",
"apiVersion": "2023-05-01",
"name": "myLoadBalancer",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard"
},
"properties": {
"frontendIPConfigurations": [
{
"name": "myFrontendIP",
"properties": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', 'myPublicIP')]"
}
}
}
],
"backendAddressPools": [
{
"name": "myBackendPool"
}
],
"loadBalancingRules": [
{
"name": "myHTTPRule",
"properties": {
"frontendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', 'myLoadBalancer', 'myFrontendIP')]"
},
"backendAddressPool": {
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', 'myLoadBalancer', 'myBackendPool')]"
},
"protocol": "Tcp",
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"disableOutboundSnat": false
}
}
],
"healthProbes": [
{
"name": "myHealthProbe",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
]
}
}