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.
π Please sign in to launch lab.
ποΈ Pre-Provisioned Environment
The following Azure resources have been pre-deployed in your environment:
Resource Overview
Resource Type | Resource Name | Configuration | Purpose |
---|---|---|---|
Resource Group | rg-internal-lb-lab | Contains all lab resources | Logical container |
Virtual Network | lab-vnet | Private network space | Network foundation |
Subnet | web-subnet | Web server subnet | Backend server network |
Web Server 1 | web-server-1 | NGINX with βServer 1β content | Backend target |
Web Server 2 | web-server-2 | NGINX with βServer 2β content | Backend target |
Test VM | test-vm | Ubuntu with testing tools | Load 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
Resource | Username | Password |
---|---|---|
All VMs | azureuser | LabPassword123! |
π Lab Exercises
Part 1: Verify Pre-Provisioned Environment
Step 1: Navigate to Resource Group
- Open the Azure Portal
- Search for and select Resource groups
- Click on your lab resource group
Step 2: Verify Resources
Confirm the following resources are present:
Resource | Type | Expected Status |
---|---|---|
web-server-1 | Virtual Machine | β Running |
web-server-2 | Virtual Machine | β Running |
test-vm | Virtual Machine | β Running |
lab-vnet | Virtual Network | β Available |
web-subnet | Subnet | β Configured |
Step 3: Note Private IP Addresses
- Click on each VM to view its Overview page
- Record the Private IP addresses:
VM | Private IP | Notes |
---|---|---|
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
- In the Azure Portal, click on test-vm
- Click Connect β SSH
- 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:
# 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 hostnamesnslookup web-server-1nslookup 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
- In your resource group, click + Create
- Search for βLoad balancerβ
- Select Load balancer by Microsoft
- Click Create
Step 2: Configure Basic Settings
Setting | Value | Notes |
---|---|---|
Subscription | Your subscription | Pre-selected |
Resource group | Your lab resource group | Pre-selected |
Name | web-app-lb | Descriptive name |
Region | Same as resource group | Must match VMs |
SKU | Standard | Required for advanced features |
Type | Internal | Private network only |
Tier | Regional | Single region deployment |
Step 3: Configure Frontend IP
- Click Next: Frontend IP configuration
- Click + Add a frontend IP configuration
Setting | Value | Notes |
---|---|---|
Name | WebAppFrontend | Frontend identifier |
IP version | IPv4 | Standard protocol |
Virtual network | lab-vnet | Target network |
Subnet | web-subnet | Backend subnet |
IP assignment | Dynamic | Let Azure assign IP |
Availability zone | No Zone | Single zone for lab |
- Click Add
Step 4: Skip Backend Pools (For Now)
- Click Next: Backend pools
- Click Next: Inbound rules (weβll configure pools later)
Step 5: Complete Creation
- Click Next: Outbound rules
- Click Next: Tags (optional)
- Click Review + create
- Review the configuration
- Click Create
β±οΈ Deployment Time: Typically takes 2-3 minutes to complete.
Part 4: Configure Backend Pool
Step 1: Navigate to Load Balancer
- Go to your resource group
- Click on web-app-lb
- Wait for deployment to complete if still in progress
Step 2: Create Backend Pool
- In the left menu, select Backend pools
- Click + Add
Step 3: Configure Backend Pool Settings
Setting | Value | Notes |
---|---|---|
Name | WebServersPool | Pool identifier |
Virtual network | lab-vnet | Target network |
Backend Pool Configuration | IP address | Use VM IP addresses |
IP version | IPv4 | Match frontend |
Step 4: Add Web Servers
- Under IP addresses, click + Add
- 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
- 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
- In your load balancer, click Health probes in the left menu
- Click + Add
Step 2: Configure Health Probe
Setting | Value | Purpose |
---|---|---|
Name | WebHealthProbe | Probe identifier |
Protocol | HTTP | Web service protocol |
Port | 80 | Standard HTTP port |
Path | / | Root page check |
Interval | 15 seconds | Check frequency |
Unhealthy threshold | 2 failures | Failover trigger |
Step 3: Save Health Probe
- Click OK
- 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
- In your load balancer, click Load balancing rules
- Click + Add
Step 2: Configure Load Balancing Rule
Setting | Value | Notes |
---|---|---|
Name | WebAppRule | Rule identifier |
IP Version | IPv4 | Match frontend |
Frontend IP address | WebAppFrontend | Previously created |
Protocol | TCP | Transport protocol |
Port | 80 | HTTP port |
Backend port | 80 | Same as frontend |
Backend pool | WebServersPool | Target pool |
Health probe | WebHealthProbe | Health monitoring |
Step 3: Advanced Settings
Setting | Value | Purpose |
---|---|---|
Session persistence | None | Round-robin distribution |
Idle timeout | 4 minutes | Connection timeout |
TCP reset | Disabled | Default setting |
Floating IP | Disabled | Standard configuration |
Step 4: Save Rule
- Click OK
- Wait for the rule to be created
Part 7: Test Load Balancer Functionality
Step 1: Get Load Balancer Private IP
- In your load balancer, click Overview
- Note the Private IP address under Frontend IP configuration
- Record this IP:
[load-balancer-private-ip]
Step 2: Connect to Test VM
- Return to your SSH session on test-vm
- If disconnected, reconnect using the same method as before
Step 3: Test Load Distribution
# Single test requestcurl http://[load-balancer-private-ip]
# Multiple requests to see distributionecho "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
# Watch load balancing in real-timewhile true; do echo "$(date): $(curl -s http://[load-balancer-private-ip])" sleep 2done
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
- In Azure Portal, navigate to your load balancer
- Click Backend pools β WebServersPool
- Observe: Both servers should show as Healthy
Step 2: Simulate Server Failure
- Go to your resource group
- Click on web-server-1
- Click Stop in the toolbar
- Confirm the stop action
Step 3: Monitor Health Changes
- Return to the backend pool view
- Wait 30-60 seconds for health probe to detect the failure
- Observe: web-server-1 should show as Unhealthy
Step 4: Test Failover Behavior
From your test VM SSH session:
# Test during failoverecho "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
- Go back to web-server-1 in the Azure Portal
- Click Start in the toolbar
- Wait for the VM to fully start
- Monitor: Server should return to Healthy status
- Test: Traffic should resume to both servers
Part 9: Advanced Testing & Configuration
Step 1: Configure Session Persistence
- Navigate to Load balancing rules β WebAppRule
- Click Edit
- Change Session persistence to Client IP
- Click Save
Step 2: Test Session Persistence
# Test sticky sessionsecho "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
- Change Session persistence back to None
- Test again to confirm round-robin behavior returns
Step 4: Monitor Performance Metrics
- In your load balancer, click Metrics
- Explore key metrics:
Metric | Purpose |
---|---|
Data path availability | Overall health percentage |
Health probe status | Backend server health |
Packet count | Internal traffic volume |
Byte count | Data transferred |
π§ Troubleshooting Guide
Common Issues and Solutions
Issue | Possible Cause | Solution |
---|---|---|
Load balancer doesnβt respond | Incorrect private IP | Verify frontend IP configuration |
Canβt connect to test VM | NSG blocking SSH | Check NSG rules allow port 22 |
Health probe fails | Web service not running | Verify NGINX is running on web servers |
All traffic to one server | Session persistence enabled | Check load balancing rule settings |
Slow failover detection | Health probe interval too long | Reduce probe interval |
Health Status Meanings
Status | Description | Action |
---|---|---|
Healthy | Server responding to probes | No action needed |
Unhealthy | Server failing health checks | Check server status |
Unknown | Initial state or transitioning | Wait 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:
- Multiple Subnets: Deploy load balancer across different subnets
- Custom Health Checks: Create specific health check endpoints
- Port-based Rules: Configure different ports for different services
- Network Security: Test with restrictive NSG rules
- 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