# Improve application scalability and resiliency by using Azure Load Balancer

# Random Notes

  • The default distribution mode is five-tuple hash.
  • Availability sets can be used to ensure VMs are created on different physical servers.
  • Availability zones can be used to ensure VMs are created at different locations within a region.
  • Remote Desktop Gateway is a Windows service that you can use to enable clients on the internet to make Remote Desktop Protocol (RDP) connections through firewalls to Remote Desktop servers on your private network. The default five-tuple hash in Load Balancer is incompatible with this service. If you want to use Load Balancer with your Remote Desktop servers, use source IP affinity.
  • Another use case for source IP affinity is media upload. In many implementations, a client initiates a session through a TCP protocol and connects to a destination IP address. This connection remains open throughout the upload to monitor progress, but the file is uploaded through a separate UDP protocol.
    • With the five-tuple hash, the load balancer likely will send the TCP and UDP connections to different destination IP addresses and the upload won't finish successfully. Use source IP affinity to resolve this issue.

# Specify the distribution mode for the Load Balancer

$lb = Get-AzLoadBalancer -Name MyLb -ResourceGroupName MyResourceGroup
$lb.LoadBalancingRules[0].LoadDistribution = 'sourceIp'
Set-AzLoadBalancer -LoadBalancer $lb
1
2
3

# Create an external Load Balancer

# Create the VMs and put them in an availability set

git clone https://github.com/MicrosoftDocs/mslearn-improve-app-scalability-resiliency-with-load-balancer.git
cd mslearn-improve-app-scalability-resiliency-with-load-balancer
1
2
bash create-high-availability-vm-with-sets.sh learn-420a7657-8648-43b4-82ea-3d9fff401741
1

# Create a public IP address

az network public-ip create \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --allocation-method Static \
  --name myPublicIP
1
2
3
4

# Create the Load Balancer

az network lb create \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --name myLoadBalancer \
  --public-ip-address myPublicIP \
  --frontend-ip-name myFrontEndPool \
  --backend-pool-name myBackEndPool
1
2
3
4
5
6

# Create a health probe for tcp/80

az network lb probe create \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --lb-name myLoadBalancer \
  --name myHealthProbe \
  --protocol tcp \
  --port 80
1
2
3
4
5
6

# Create a Load Balancer rule to forward traffic from port 80 to the back-end on port 80

This command also uses the health probe we created.

az network lb rule create \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --lb-name myLoadBalancer \
  --name myHTTPRule \
  --protocol tcp \
  --frontend-port 80 \
  --backend-port 80 \
  --frontend-ip-name myFrontEndPool \
  --backend-pool-name myBackEndPool \
  --probe-name myHealthProbe
1
2
3
4
5
6
7
8
9
10

# Connect the virtual machine NICs to the new Load Balancer

az network nic ip-config update \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --nic-name webNic1 \
  --name ipconfig1 \
  --lb-name myLoadBalancer \
  --lb-address-pools myBackEndPool

az network nic ip-config update \
  --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
  --nic-name webNic2 \
  --name ipconfig1 \
  --lb-name myLoadBalancer \
  --lb-address-pools myBackEndPool
1
2
3
4
5
6
7
8
9
10
11
12
13

# Get the public IP of the Load Balancer

echo http://$(az network public-ip show \
                --resource-group learn-420a7657-8648-43b4-82ea-3d9fff401741 \
                --name myPublicIP \
                --query ipAddress \
                --output tsv)
1
2
3
4
5

# Create an internal Load Balancer

  • Internal load balancers require a private IP instead of a public IP.
  • VMs calling the load balancer must be in the same subnet, but the target VMs can be in a separate subnet.
Last Updated: 3/7/2022, 9:55:04 PM