Overview
This template provides a production‑ready HAProxy instance as a Monk runnable. You can:- Run it directly to get a managed HAProxy load balancer with sensible defaults
- Inherit it in your own runnable to seamlessly add load balancing and high availability to your services
What this template manages
- HAProxy container (
haproxyimage, configurable tag) - Network service on port 8080 (configurable)
- Custom HAProxy configuration file
- Backend server routing and health checking
- Connection timeouts and load balancing algorithms
Quick start (run directly)
- Load templates
- Run HAProxy with defaults
- Customize backend servers (recommended via inheritance)
variables. To point HAProxy at your own backend servers:
- Preferred: inherit and override variables with your backend configuration as shown below.
- Alternative: fork/clone and edit the
variablesinhaproxy.yml, thenmonk load MANIFESTand run.
host-port-number) and forward traffic to the configured backend servers.
Configuration
Key variables you can customize in this template:haproxy.cfg) is located in the files/ directory and can be customized before running. The template uses Monk’s variable substitution ({{ v "variable-name" }}) to inject runtime configuration.
Use by inheritance (recommended for apps)
Inherit the HAProxy runnable in your application to add load balancing. Example:haproxy.cfg file to define multiple backend servers, health checks, and routing rules.
Ports and connectivity
- Service:
haproxyon TCP port8080(configurable viahaproxy-port-number) - Host exposure: Port
8080(configurable viahost-port-number) - From other runnables in the same process group, use
connection-hostname("\<connection-name>")to resolve the load balancer.
Persistence and configuration
- Configuration file:
files/haproxy.cfg- mounted to/usr/local/etc/haproxy/haproxy.cfgin the container - The configuration supports Monk variable interpolation for dynamic backend configuration
- No persistent data storage required (HAProxy is stateless)
Features
- Layer 4 (TCP) and Layer 7 (HTTP) load balancing
- SSL/TLS termination
- Health checking with automatic failover
- Sticky sessions (session affinity)
- Advanced routing and URL rewriting
- ACL-based traffic rules
- High performance (100K+ concurrent connections)
- Built-in DNS resolution for dynamic backends
Related templates
- See other templates in this repository for complementary services
- Combine with monitoring tools (
prometheus-grafana/) for observability - Use with application servers (
nginx/,apache/) for complete web stack - Integrate with your application stack as needed
Troubleshooting
- Check logs:
- If backend servers are not responding, verify the
backend-hostnameandbackend-portvalues match your backend configuration. - Ensure backend servers are reachable from the HAProxy container’s network.
- For custom configurations, validate your
haproxy.cfgsyntax before running.