When running a highly available Kubernetes cluster with multiple control plane nodes, you need a load balancer to distribute API traffic across all control plane endpoints. This guide walks through setting up HAProxy 3.2 on Debian to load balance both the Kubernetes API (port 6443) and Talos API (port 50000).
Architecture Overview
| Component | Address | Port | Purpose |
|---|---|---|---|
| HAProxy LB | 192.168.66.160 | 6443 | Kubernetes API |
| HAProxy LB | 192.168.66.160 | 50000 | Talos API |
| HAProxy LB | 192.168.66.160 | 9600 | Stats Dashboard |
| Control Plane 1 | 192.168.66.161 | 6443/50000 | talos-lon-cp01 |
| Control Plane 2 | 192.168.66.162 | 6443/50000 | talos-lon-cp02 |
| Control Plane 3 | 192.168.66.163 | 6443/50000 | talos-lon-cp03 |
Prerequisites
- Debian Trixie (or compatible) server for the load balancer
- Network connectivity to all control plane nodes
- Root or sudo access on the load balancer server
Install HAProxy 3.2
HAProxy 3.2 is available from the official HAProxy Debian repository. First, add the repository signing key and apt source:
| |
Update the package cache and install HAProxy:
Enable and start the HAProxy service:
Verify HAProxy is running:
| |
Configure HAProxy
Edit the HAProxy configuration file at /etc/haproxy/haproxy.cfg. Replace the default configuration with the following:
| |
Configuration Breakdown
Global Section
The global section configures HAProxy process-wide settings:
- chroot: Runs HAProxy in a chroot jail for security
- stats socket: Enables runtime API for dynamic configuration
- ssl-default-bind-*: Sets secure TLS defaults following Mozilla’s intermediate profile
Defaults Section
The defaults section sets values inherited by all frontends and backends:
- mode http: Default mode (overridden to TCP for our API proxying)
- timeout connect/client/server: Connection timeout values in milliseconds
Stats Dashboard
The stats listener provides a web-based dashboard to monitor HAProxy:
- Bound to port 9600 on the load balancer IP
- Protected with basic authentication
- Restricted to specific networks via ACL
- Auto-refreshes every 10 seconds
Security Note: Update the
stats authpassword andallowed_networksACL to match your environment. Consider using a more restrictive network range.
Kubernetes API Frontend/Backend
The k8s_apiserver frontend and k8s_controlplane backend handle Kubernetes API traffic:
- mode tcp: TCP passthrough (required for TLS termination at the API server)
- option ssl-hello-chk: Health checks using SSL hello handshake
- option httpchk GET /healthz: HTTP health check endpoint
- balance roundrobin: Distributes requests evenly across servers
Talos API Frontend/Backend
The talos_apiserver frontend and talos_controlplane backend follow the same pattern for Talos API traffic on port 50000.
Apply Configuration
Validate the configuration syntax:
| |
Restart HAProxy to apply changes:
| |
Verify the Setup
Check that HAProxy is listening on the configured ports:
| |
Expected output:
tcp 0 0 192.168.66.160:9600 0.0.0.0:* LISTEN 5712/haproxy tcp 0 0 192.168.66.160:6443 0.0.0.0:* LISTEN 5712/haproxy tcp 0 0 192.168.66.160:50000 0.0.0.0:* LISTEN 5712/haproxy
Test connectivity to the Kubernetes API through the load balancer:
| |
Configure Talos and kubectl
Update your talosconfig to use the load balancer endpoint:
| |
When generating Talos cluster configuration, use the load balancer IP as the endpoint:
| |
Your kubeconfig should point to the load balancer:
Monitoring
Access the HAProxy stats dashboard at:
http://192.168.66.160:9600/
The dashboard shows:
- Backend server health status (green/red)
- Current connections and request rates
- Bytes in/out per server
- Response time metrics
High Availability Considerations
For production environments, consider these enhancements:
- Redundant Load Balancers: Deploy multiple HAProxy instances with keepalived or a cloud load balancer in front
- Health Check Tuning: Adjust
inter,fall, andriseparameters for faster failover:1server talos-lon-cp01 192.168.66.161:6443 check inter 2000 fall 3 rise 2 - Connection Limits: Set
maxconnto prevent overload - Logging: Configure rsyslog to capture HAProxy logs for troubleshooting
Summary
You now have HAProxy 3.2 configured to load balance:
- Kubernetes API on port 6443 across 3 control plane nodes
- Talos API on port 50000 across 3 control plane nodes
- Stats dashboard on port 9600 for monitoring
This setup provides a single stable endpoint for your Talos Kubernetes cluster, enabling high availability and simplified client configuration.