Skip to content

Load Balancer - Internal

🎯 Lab Objective

In this hands-on lab, you will learn how to:

  • Create and configure an Azure Internal Load Balancer for private network traffic distribution
  • Set up backend pools with virtual machines for internal load distribution
  • Configure health probes for automatic backend health monitoring
  • Create load balancing rules for internal traffic routing
  • Test load distribution and validate high availability scenarios
  • Understand the differences between internal and external load balancers

Goal: Configure an Internal Load Balancer to distribute traffic between web servers within your private network.


πŸ—οΈ Pre-Provisioned Environment

The following Azure resources have been pre-deployed in your environment:

Resource Overview

Resource TypeResource NameConfigurationPurpose
Resource Grouprg-internal-lb-labContains all lab resourcesLogical container
Virtual Networklab-vnetPrivate network spaceNetwork foundation
Subnetweb-subnetWeb server subnetBackend server network
Web Server 1web-server-1NGINX with β€œServer 1” contentBackend target
Web Server 2web-server-2NGINX with β€œServer 2” contentBackend target
Test VMtest-vmUbuntu with testing toolsLoad balancer client

Network Architecture

lab-vnet (Private Network)
└── web-subnet
β”œβ”€β”€ web-server-1 (NGINX - "Web Server 1")
β”œβ”€β”€ web-server-2 (NGINX - "Web Server 2")
β”œβ”€β”€ test-vm (Testing client)
└── Internal Load Balancer (to be created)

Default Credentials

ResourceUsernamePassword
All VMsazureuserLabPassword123!

πŸš€ Lab Exercises

Part 1: Verify Pre-Provisioned Environment

Step 1: Navigate to Resource Group

  1. Open the Azure Portal
  2. Search for and select Resource groups
  3. Click on your lab resource group

Step 2: Verify Resources

Confirm the following resources are present:

ResourceTypeExpected Status
web-server-1Virtual Machineβœ… Running
web-server-2Virtual Machineβœ… Running
test-vmVirtual Machineβœ… Running
lab-vnetVirtual Networkβœ… Available
web-subnetSubnetβœ… Configured

Step 3: Note Private IP Addresses

  1. Click on each VM to view its Overview page
  2. Record the Private IP addresses:
VMPrivate IPNotes
web-server-1.._.Backend server
web-server-2.._.Backend server
test-vm.._.Test client

Part 2: Test Individual Web Servers

Before creating the load balancer, verify each web server works independently.

Step 1: Connect to Test VM

  1. In the Azure Portal, click on test-vm
  2. Click Connect β†’ SSH
  3. Use one of these methods:
    • Azure Cloud Shell: Click Go to Azure Cloud Shell
    • Native SSH: Use the provided command
    • Azure Bastion: If available in your lab

Step 2: Test Web Server Connectivity

Once connected to the test VM, run these commands:

Terminal window
# Test web-server-1 (replace with actual IP)
curl http://[web-server-1-private-ip]
# Test web-server-2 (replace with actual IP)
curl http://[web-server-2-private-ip]
# Alternative: Use nslookup to resolve hostnames
nslookup web-server-1
nslookup web-server-2

Expected Results:

  • web-server-1 should return: β€œWelcome from Web Server 1”
  • web-server-2 should return: β€œWelcome from Web Server 2”

πŸ’‘ Troubleshooting: If connections fail, verify the VMs are running and NSG rules allow port 80 traffic.


Part 3: Create the Internal Load Balancer

Step 1: Start Load Balancer Creation

  1. In your resource group, click + Create
  2. Search for β€œLoad balancer”
  3. Select Load balancer by Microsoft
  4. Click Create

Step 2: Configure Basic Settings

SettingValueNotes
SubscriptionYour subscriptionPre-selected
Resource groupYour lab resource groupPre-selected
Nameweb-app-lbDescriptive name
RegionSame as resource groupMust match VMs
SKUStandardRequired for advanced features
TypeInternalPrivate network only
TierRegionalSingle region deployment

Step 3: Configure Frontend IP

  1. Click Next: Frontend IP configuration
  2. Click + Add a frontend IP configuration
SettingValueNotes
NameWebAppFrontendFrontend identifier
IP versionIPv4Standard protocol
Virtual networklab-vnetTarget network
Subnetweb-subnetBackend subnet
IP assignmentDynamicLet Azure assign IP
Availability zoneNo ZoneSingle zone for lab
  1. Click Add

Step 4: Skip Backend Pools (For Now)

  1. Click Next: Backend pools
  2. Click Next: Inbound rules (we’ll configure pools later)

Step 5: Complete Creation

  1. Click Next: Outbound rules
  2. Click Next: Tags (optional)
  3. Click Review + create
  4. Review the configuration
  5. Click Create

⏱️ Deployment Time: Typically takes 2-3 minutes to complete.


Part 4: Configure Backend Pool

Step 1: Navigate to Load Balancer

  1. Go to your resource group
  2. Click on web-app-lb
  3. Wait for deployment to complete if still in progress

Step 2: Create Backend Pool

  1. In the left menu, select Backend pools
  2. Click + Add

Step 3: Configure Backend Pool Settings

SettingValueNotes
NameWebServersPoolPool identifier
Virtual networklab-vnetTarget network
Backend Pool ConfigurationIP addressUse VM IP addresses
IP versionIPv4Match frontend

Step 4: Add Web Servers

  1. Under IP addresses, click + Add
  2. Add both web servers:

Web Server 1:

  • Virtual machine β†’ Select web-server-1
  • Network IP configuration β†’ Select the IP configuration
  • Click Add

Web Server 2:

  • Virtual machine β†’ Select web-server-2
  • Network IP configuration β†’ Select the IP configuration
  • Click Add
  1. Click Save

πŸ” Verification: You should see both VMs listed with their private IP addresses in the backend pool.


Part 5: Create Health Probe

Step 1: Navigate to Health Probes

  1. In your load balancer, click Health probes in the left menu
  2. Click + Add

Step 2: Configure Health Probe

SettingValuePurpose
NameWebHealthProbeProbe identifier
ProtocolHTTPWeb service protocol
Port80Standard HTTP port
Path/Root page check
Interval15 secondsCheck frequency
Unhealthy threshold2 failuresFailover trigger

Step 3: Save Health Probe

  1. Click OK
  2. Wait for the probe to be created

πŸ’‘ How it Works: The health probe sends HTTP GET requests to each web server every 15 seconds. If 2 consecutive requests fail, the server is marked unhealthy and removed from rotation.


Part 6: Create Load Balancing Rule

Step 1: Navigate to Load Balancing Rules

  1. In your load balancer, click Load balancing rules
  2. Click + Add

Step 2: Configure Load Balancing Rule

SettingValueNotes
NameWebAppRuleRule identifier
IP VersionIPv4Match frontend
Frontend IP addressWebAppFrontendPreviously created
ProtocolTCPTransport protocol
Port80HTTP port
Backend port80Same as frontend
Backend poolWebServersPoolTarget pool
Health probeWebHealthProbeHealth monitoring

Step 3: Advanced Settings

SettingValuePurpose
Session persistenceNoneRound-robin distribution
Idle timeout4 minutesConnection timeout
TCP resetDisabledDefault setting
Floating IPDisabledStandard configuration

Step 4: Save Rule

  1. Click OK
  2. Wait for the rule to be created

Part 7: Test Load Balancer Functionality

Step 1: Get Load Balancer Private IP

  1. In your load balancer, click Overview
  2. Note the Private IP address under Frontend IP configuration
  3. Record this IP: [load-balancer-private-ip]

Step 2: Connect to Test VM

  1. Return to your SSH session on test-vm
  2. If disconnected, reconnect using the same method as before

Step 3: Test Load Distribution

Terminal window
# Single test request
curl http://[load-balancer-private-ip]
# Multiple requests to see distribution
echo "Testing load distribution..."
for i in {1..10}; do
echo "Request $i:"
curl http://[load-balancer-private-ip]
echo ""
done

Expected Results:

  • Responses should alternate between β€œWeb Server 1” and β€œWeb Server 2”
  • Traffic is distributed across both backend servers

Step 4: Continuous Testing

Terminal window
# Watch load balancing in real-time
while true; do
echo "$(date): $(curl -s http://[load-balancer-private-ip])"
sleep 2
done

Press Ctrl+C to stop the continuous test.

🎯 Success Criteria: You should see roughly equal distribution of requests between the two web servers.


Part 8: Test High Availability & Failover

Step 1: Monitor Current Health Status

  1. In Azure Portal, navigate to your load balancer
  2. Click Backend pools β†’ WebServersPool
  3. Observe: Both servers should show as Healthy

Step 2: Simulate Server Failure

  1. Go to your resource group
  2. Click on web-server-1
  3. Click Stop in the toolbar
  4. Confirm the stop action

Step 3: Monitor Health Changes

  1. Return to the backend pool view
  2. Wait 30-60 seconds for health probe to detect the failure
  3. Observe: web-server-1 should show as Unhealthy

Step 4: Test Failover Behavior

From your test VM SSH session:

Terminal window
# Test during failover
echo "Testing failover behavior..."
for i in {1..10}; do
echo "Request $i:"
curl http://[load-balancer-private-ip]
echo ""
done

Expected Results:

  • All requests should go to web-server-2 only
  • No requests should fail (high availability maintained)

Step 5: Restore Service

  1. Go back to web-server-1 in the Azure Portal
  2. Click Start in the toolbar
  3. Wait for the VM to fully start
  4. Monitor: Server should return to Healthy status
  5. Test: Traffic should resume to both servers

Part 9: Advanced Testing & Configuration

Step 1: Configure Session Persistence

  1. Navigate to Load balancing rules β†’ WebAppRule
  2. Click Edit
  3. Change Session persistence to Client IP
  4. Click Save

Step 2: Test Session Persistence

Terminal window
# Test sticky sessions
echo "Testing session persistence..."
for i in {1..10}; do
echo "Request $i:"
curl http://[load-balancer-private-ip]
echo ""
done

Expected Result: All requests should consistently go to the same server.

Step 3: Reset to Round Robin

  1. Change Session persistence back to None
  2. Test again to confirm round-robin behavior returns

Step 4: Monitor Performance Metrics

  1. In your load balancer, click Metrics
  2. Explore key metrics:
MetricPurpose
Data path availabilityOverall health percentage
Health probe statusBackend server health
Packet countInternal traffic volume
Byte countData transferred

πŸ”§ Troubleshooting Guide

Common Issues and Solutions

IssuePossible CauseSolution
Load balancer doesn’t respondIncorrect private IPVerify frontend IP configuration
Can’t connect to test VMNSG blocking SSHCheck NSG rules allow port 22
Health probe failsWeb service not runningVerify NGINX is running on web servers
All traffic to one serverSession persistence enabledCheck load balancing rule settings
Slow failover detectionHealth probe interval too longReduce probe interval

Health Status Meanings

StatusDescriptionAction
HealthyServer responding to probesNo action needed
UnhealthyServer failing health checksCheck server status
UnknownInitial state or transitioningWait for probe results

πŸ” Internal vs External Load Balancer Comparison

Internal Load Balancer

  • βœ… Private IP address within VNet
  • βœ… Internal traffic only (VNet-to-VNet, on-premises)
  • βœ… No internet exposure (enhanced security)
  • βœ… Lower cost (no public IP required)
  • ❌ Not accessible from internet

External Load Balancer

  • βœ… Public IP address for internet access
  • βœ… Internet-facing applications
  • βœ… Global accessibility
  • ❌ Higher cost (public IP required)
  • ❌ Increased attack surface

πŸ§ͺ Additional Experiments

Try these optional exercises to deepen your understanding:

  1. Multiple Subnets: Deploy load balancer across different subnets
  2. Custom Health Checks: Create specific health check endpoints
  3. Port-based Rules: Configure different ports for different services
  4. Network Security: Test with restrictive NSG rules
  5. Cross-VNet: Test load balancer with peered virtual networks

πŸŽ“ Key Takeaways

After completing this lab, you should understand:

  • Internal Load Balancers distribute traffic within private networks
  • Backend pools group internal resources for load distribution
  • Health probes ensure high availability through automatic failover
  • Session persistence affects client routing behavior
  • Private IP addressing keeps traffic within Azure networks
  • High availability is maintained even during server failures

πŸ“ˆ Load Balancer Configuration Summary

Key Components

  • Frontend IP: Private IP within your VNet
  • Backend Pool: Collection of internal servers
  • Health Probe: Monitors server availability
  • Load Balancing Rule: Defines traffic distribution

Distribution Methods

  • None (Round Robin): Requests distributed evenly
  • Client IP: Same client always goes to same server
  • Client IP and Protocol: Based on IP and protocol combination

πŸ“š Additional Resources