☁️ CloudProjectHub

Load Balancer

What is Elastic Load Balancing?

Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as EC2 instances, containers, and IP addresses. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones, improving application availability and fault tolerance.

Key Features

  • Auto-scaling: Automatically scales to handle traffic spikes
  • Health Checks: Monitors target health and routes traffic accordingly
  • Security: Integrated with AWS security services
  • High Availability: Multi-AZ deployment support
  • Integration: Works with EC2 Auto Scaling and ECS
  • Monitoring: CloudWatch metrics and access logs

Prerequisites

  • AWS Account
  • VPC with subnets in multiple Availability Zones
  • Target instances, containers, or IP addresses
  • Security groups configured
  • Understanding of load balancing concepts

Step-by-Step: Creating an Application Load Balancer

  1. Sign in to AWS Management Console: Go to console.aws.amazon.com
  2. Navigate to EC2: Go to EC2 dashboard
  3. Load Balancers: Click "Load Balancers" in the left sidebar
  4. Create Load Balancer: Click "Create Load Balancer" button
  5. Select Type: Choose Application Load Balancer
  6. Basic Configuration:
    • Name: Enter a unique name
    • Scheme: Internet-facing or Internal
    • IP address type: IPv4 or dualstack
  7. Network Mapping:
    • VPC: Select your VPC
    • Mappings: Select subnets in multiple AZs
  8. Security Groups: Select or create security groups
  9. Listeners and Routing:
    • Protocol: HTTP or HTTPS
    • Port: 80 for HTTP, 443 for HTTPS
    • Default action: Forward to target group
  10. Target Groups:
    • Name: Enter target group name
    • Protocol: HTTP or HTTPS
    • Port: Target port (e.g., 80)
    • Target type: Instance, IP, or Lambda
    • Health checks: Configure health check settings
  11. Register Targets: Add EC2 instances or other targets
  12. Review and Create: Review all settings and create the load balancer

Configuring SSL/TLS (for HTTPS)

  1. Request Certificate: Use AWS Certificate Manager (ACM)
  2. Add HTTPS Listener: Add port 443 listener to load balancer
  3. Select Certificate: Choose ACM certificate
  4. Security Policy: Select appropriate SSL/TLS policy
  5. Update Security Groups: Allow HTTPS traffic (port 443)

Setting up Auto Scaling

  1. Create Launch Template: Define EC2 instance configuration
  2. Create Auto Scaling Group:
    • Choose launch template
    • Select VPC and subnets
    • Set minimum and maximum instances
    • Configure scaling policies
  3. Attach to Load Balancer: Add ASG to target group
  4. Test Scaling: Monitor scaling events

Best Practices

  • Use multiple Availability Zones for high availability
  • Enable cross-zone load balancing
  • Configure appropriate health checks
  • Use SSL/TLS termination at the load balancer
  • Implement proper security groups
  • Monitor performance with CloudWatch
  • Use connection draining for graceful shutdowns
  • Implement logging and access logs

Load Balancer Types

  • Application Load Balancer (ALB): Layer 7, HTTP/HTTPS, content-based routing
  • Network Load Balancer (NLB): Layer 4, TCP/UDP, ultra-high performance
  • Gateway Load Balancer (GWLB): Layer 3 gateway, third-party appliances
  • Classic Load Balancer (CLB): Legacy, basic load balancing

Common Use Cases

  • Web application load balancing
  • Microservices architecture
  • Container-based applications (ECS/EKS)
  • API gateway and management
  • SSL/TLS termination
  • Content-based routing
  • Blue-green deployments
  • Auto-scaling web applications