docker-archive / dockercloud-haproxy

HAproxy image that autoreconfigures itself when used in Docker Cloud
https://cloud.docker.com/
651 stars 187 forks source link

Draining connections to backend #205

Closed aczarnecki closed 6 years ago

aczarnecki commented 7 years ago

Hi, I'm currently working with some (unfortunately) stateful apps on AWS. I reached the point where I need to configure scaling for the application. And when scaling up there is no problem (thanks to this proxy) I have some issues when scaling down. Namely I need to set up connection draining and wait for users before I can turn down the server.

I'm working with Docker v13.1 and Swarm Mode.

Is there a way to drain connections to some backend in a way that it would be persisted? And also how to check if there are no more connection to that backend (or when was the last one)? Maybe this could be achieved by using socket commands (https://cbonte.github.io/haproxy-dconv/1.6/management.html#9.2). Something like: set server <backend> state drain We can possibly get the server/container name from: docker stack ps <stack_name> It would be nice to know how to get to the socket as well. According to haproxy docs it should be something like:

# socat /var/run/haproxy readline
   prompt
   > show info
   ...
   >

Do any of You know how can this be achieved in the Docker container?

tifayuki commented 7 years ago

Never tried it before, but I think you can: 1) you can publish the port 1936 to see the stats of haproxy and each backend server. 2) to set the stats socket /var/run/haproxy.sock mode 600 level admin, you can use the EXTRA_GLOBAL_SETTINGS environment variable 3) to run the socat command, you can either exec into the haproxy container, or mount /var/run/ volume so that you can directly access the unix socket on the node.