Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Service routing with Consul & HAProxy

Avatar for cldmnky cldmnky
September 08, 2016

Service routing with Consul & HAProxy

From Stockholm HashiCorp User Group meetup #1, Sept 8, 2016.

Avatar for cldmnky

cldmnky

September 08, 2016

More Decks by cldmnky

Other Decks in Technology

Transcript

  1. stats ~  300  deploys  /  week   ~  800  new

     containers  /  week   ~  2k  req’s  /  sec  on  haproxy  
  2. tools? not  batteries  included  but  removable,   but  rather  just

     the  bag  of  batteries   for  us  to  play  with!
  3. Consul… HTTP  api:   $  curl  localhost:8500/v1/catalog/services   {  

       "consul":  [],      "redis":  [],      "postgresql":  [          "master",          "slave"      ]   }
  4. templating … <h1>Dashboard for: {{datacenters | join " "}}</h1> {{range

    services}} {{range service .Name "any"}} <p> Name: {{.Name}} Tags: {{range .Tags}}{{.}}{{end}} Status: {{if ne .Status "passing"}}<span style="background- color:red">{{.Status}} state!</span>{{end}} {{if eq .Status "passing"}}<span style="background- color:green;">Ok</span>{{end}} </p> {{end}} {{end}} …
  5. feeding  HAProxy frontends  (in)   frontend http-in bind 0.0.0.0:80 mode

    http {{range $key, $pairs := tree "env/prod/haproxy/sites/" | explode }} {{ if $pairs }}{{ if $pairs.backends }} acl {{$key}}-host hdr_beg(host) -i {{$pairs.backends}}. use_backend {{$key}}-servers if {{$key}}-host {{end}}{{end}} {{end}}
  6. feeding  HAProxy frontends  (in)   frontend http-in bind 0.0.0.0:80 mode

    http acl api-host hdr_beg(host) -i production.api. use_backend api-servers if api-host
  7. feeding  HAProxy backends  (server)   {{range $key, $pairs := tree

    "env/prod/haproxy/sites" | explode }} {{ if $pairs }} backend {{$key}}-servers {{ if eq (or $pairs.mode "http") "http" }} option httpchk {{or $pairs.httpchk "GET /healthz"}} {{ end }} http-response set-header X-App {{$key}} # servers{{$backends := or $pairs.backends "localhost"}} {{range service $backends}} server {{.Node}}_{{.Port}} {{.Address}}: {{.Port}} check {{end}} {{end}} {{end}}
  8. feeding  HAProxy backends  (server)   backend api-servers option httpchk GET

    /healthz balance roundrobin http-response set-header X-App api # servers server app141_20081 10.0.0.141:20081 check server app159_20106 10.0.0.159:20106 check
  9. takeaways    Simple,  Modular  &          

                  Composable
  10. takeaways    Simple,  Modular  &          

                  Combustible