kamal
kamal copied to clipboard
Handle loadbalancing for multiple web hosts
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
loadbalancerkey 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:
- It's familiar to existing users
- Reuses code we already have
- Makes sense conceptually
- 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:
- You add a
loadbalancersetting, OR - 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.