To build & run direct from this Gist, run the following commands:
docker build -t consul-haproxy https://gist.github.com/229668c0466b840e8e8e816bc9ed9ec5.git
docker run --rm -it -p 9000:9000 -p 8000:8000 consul-haproxy
- View the load-balanced site at: http://0.0.0.0:8000/
- View the haproxy statistics page: http://0.0.0.0:9000/haproxy_stats (with username
access
and passwordsecret
)
This uses the demo.consul.io nyc3 Consul cluster, which has web
service with multiple nodes attached. If/when nodes are added/removed, or any of the Consul template values change, the load balancer is automatically reloaded gracefully with the new values using consul-template
by sending haproxy a SIGHUP kill signal.