Public | Automated Build

Last pushed: 4 months ago
Short Description
HAProxy with zero-downtime reconfiguration based on etcd
Full Description

haproxy combined with confd for HTTP load balancing


I apologise but I don't have the time to properly document this right now.
What's important to know:

  • HAProxy 1.5.x backed by Confd 1.7.0 beta 1
  • Uses zero-downtime reconfiguration (e.g - instead of harpy reload, which will drop all connections, will gradually transfer new connections to the new config)
  • Added support for url rexeg (not reggae, damn you spell checker) for routing, in addition to the usual hostname pattern
  • Added validation for existence of keys in backing kv store, to prevent failures

Create the paths allowing confd to find the services:

etcdctl mkdir "/haproxy-discover/services"
etcdctl mkdir "/haproxy-discover/tcp-services"

Depending on your needs, create one or more services or tcp-services.
For instance, to create an http service named myapp linked to the domain and load balancing on servers (we'll call it nodeA) and (called nodeB), run these commands:

etcdctl set "/haproxy-discover/services/myapp/domain" ""
etcdctl set "/haproxy-discover/services/myapp/upstreams/nodeA" ""
etcdctl set "/haproxy-discover/services/myapp/upstreams/nodeB" ""

Start the container making sure to expose port 80 on the host machine

docker run -e ETCD_NODE= -p 1000:1000 -p 80:8080 yaronr/haproxy-confd

To add an upstream node, let's say nodeB2,, you just have to run this, and the configuration should safely be updated !

etcdctl set "/haproxy-discover/services/myapp/upstreams/nodeB2" ""

To remove an upstream server, let's say ... nodeB2 (added by mistake ?), just run

etcdctl rm "/haproxy-discover/services/myapp/upstreams/nodeB2"

To remove a service, and so a directory, you must type

etcdctl rmdir "/haproxy-discover/services/myapp"

The commands for a tcp-service are the same but with tcp-services instead of services

Have fun !

Docker Pull Command
Source Repository

Comments (4)
2 years ago

The HAProxy container crashes few times a day. I can't understand why, nothing in the docker logs for that container nor in the journalctl.

I can't identify the reason or when it happens (maybe while an operation is taking place) and this means I can't identify if what my client experiences is a bug in the client or a backend issue.

2 years ago

url routing is here, sorry I missed it in the source code

{{$key := printf "/services/%s/url_reg" $service}}  {{if exists $key}}
acl host_{{$service}} url_reg -i {{getv $key}}

This is perfect thank you!

2 years ago

So no support for url routing via etcd config yet I am to assume? Strictly intended for load balancing?

3 years ago

please check yaronr/discovery - a (i think) better approach to service discovery