Skip to content
Permalink
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:

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

defaults
    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 \
  -template="/tmp/haproxy.conf.ctmpl:/etc/haproxy/haproxy.conf"

Here is an example of what the file may render:

global
    daemon
    maxconn 4

defaults
    mode default
    timeout 5

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