Hi, I've set up haproxy in a docker swarm environment to balance
between several servers.  The server task (let's call it foosrv) are
configured using docker's `replicate` directive to run on multiple
nodes, and as such, I don't have hostnames or IP addresses until
runtime.  Luckily, the docker overlay network provides a handy DNS
record which facilitates finding my foosrv tasks.

A DNS lookup of `tasks.foosrv` resolves to an array of IP addresses
for each of my replicated foosrv tasks.  Seems like a perfect fit for
the server-template directive, and it is.  The wrinkle is, I'm not
sure how exactly to use the params* in this scenario. According to the
documentation, `server-template` takes all the same params as
`server`.  Some of those params though, require an argument which
would depend on the actual backend server.

In my case, I need to configure sticky sessions using the cookie param
which requires you to pass a value.  Based on reading the docs it
looks like it would look something like this:

server-template srv 3 tasks.foosrv:80 check cookie foocookie insert

# would be equivalent to:
server srv1 check cookie foocookie insert
server srv2 check cookie foocookie insert
server srv3 check cookie foocookie insert

As you can see the entire group shares the same cookie value, which
doesn't work for my purposes as the replicas have no shared state.  Is
there any ability to add some sort of template variable based on the
`num`?  Some other way to accomplish what I need?


Please consider the environment before printing this message.

Reply via email to