Skip to content

Conversation

@mhenrixon
Copy link

@mhenrixon mhenrixon commented Apr 11, 2025

Adding Load Balancer to Kamal

This PR adds load balancing to Kamal with minimal changes. It spreads traffic across multiple app servers while keeping things simple.

Key Design Choices

Simple Approach

  • Uses an unreleased kamal-proxy image as the load balancer
  • Add a loadbalancer key to your proxy settings
  • Works automatically when you have multiple web hosts

Easy Integration

  • Managed through existing proxy commands
  • Updates automatically during deployments
  • Works without configuration when multiple web hosts are detected

Configuration Options

  • Set a specific host: loadbalancer: lb.example.com
  • Or use default: first host becomes the load balancer
  • Handles port mapping (80/443) and SSL automatically

Why We Did It This Way

We built the load balancer into the proxy system because:

  1. It's familiar to existing users
  2. Reuses code we already have
  3. Makes sense conceptually
  4. Requires minimal setup

How It Works

  • Added load balancer capability to the proxy system
  • Auto-detects when load balancing should be used
  • Created simple commands for managing it
  • Made it work with the normal deployment process

Configuration Example

proxy:
  hosts:
    - web-1.example.com
    - web-2.example.com
  loadbalancer: lb.example.com  # Optional - uses first host if not specified
  ssl: true

To turn off load balancing when using multiple roles:

proxy:
  hosts:
    - web-1.example.com
    - web-2.example.com
  loadbalancer: false
  ssl: true

Usage

Load balancing turns on when:

  1. You add a loadbalancer setting, OR
  2. You have multiple hosts

Basic commands:

kamal proxy loadbalancer start    # Start it
kamal proxy loadbalancer stop     # Stop it
kamal proxy loadbalancer deploy   # Update config
kamal proxy loadbalancer info     # Check status
kamal proxy loadbalancer logs     # View logs

Future Plans

We can add more features later:

  • Better load balancing methods
  • Health checks
  • Custom routing

This simple approach makes load balancing available to everyone without complicated setup.

@mhenrixon mhenrixon force-pushed the feat/loadbalancing branch from 3da7b51 to a1d1046 Compare May 19, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants