Skip to content
Branch: master
Find file Copy path
Find file Copy path
Seth Vargo Move examples to a folder 5c10da7 Sep 22, 2016
0 contributors

Users who have contributed to this file

49 lines (37 sloc) 1.39 KB

HAProxy Consul Template Example

HAProxy is a very common load balancer. You can read more about the HAProxy configuration file syntax in the HAProxy documentation.

Global Service Load Balancer

Here is an example template for rendering an HAProxy configuration file with Consul Template:

    maxconn {{key "service/haproxy/maxconn"}}

    mode {{key "service/haproxy/mode"}}{{range ls "service/haproxy/timeouts"}}
    timeout {{.Key}} {{.Value}}{{end}}

listen http-in
    bind *:8000{{range service "release.web"}}
    server {{.Node}} {{.Address}}:{{.Port}}{{end}}

Save this file to disk at a place reachable by the Consul Template process like /tmp/haproxy.conf.ctmpl and run Consul Template:

$ consul-template \

Here is an example of what the file may render:

    maxconn 4

    mode default
    timeout 5

listen http-in
    bind *:8000
    server nyc3-worker-2
    server nyc3-worker-3
    server nyc3-worker-1
You can’t perform that action at this time.