High availability on SWARM


I have two swarm nodes (manager, worker) where I’ve installed mariadb galera cluster with docker containers. This part works properly.
In one node I have a load balancer (haproxy or pen) to make a load balancer. The load balancer works fine and the services are running but I want to have high availability in this infrastructure. Normally I install haproxy with keepalived to do this, but in this case, I don’t have idea to do this in docker. The main problem I have is the VIP of keepalived, how can I access to this IP from external clients?

Any ideas?

Thanks in advance

I think for HA on swarm you need an L3 proxy routing ports to nodes that are exposing the ports for your application provided it can handle multiple instances.

First, thanks for your reply
Do you refer to exposing ports with -P option?

I do this for the load balancer but I don’t know how i should do with Virtual IP of keep alived.

More or less this is the architecture that I need. Is in the yellow part where I’m confused.
Any ideas?

With the -p but yes. As for the yellow area not really sure.

You don’t need keepalived, as swarm mode comes with integrated routing mesh.

Just start as much replicas as you need with exposed port:
docker service create --name my-ha-loadbalancer -p 3306:3306 --replicas 2 your-load-balancer-image

You can now acces your lb-instances from outside the cluster by any.public.ip:3306 and from inside your cluster by using the service name (my-ha-loadbalancer:3306)

For more information see: https://docs.docker.com/engine/swarm/ingress/

1 Like

Thanks for your reply

In this case I need the external clients or applications pointing to 2 public.ip:3306, right?
There is some way to access with my.servicename:3306 from outside like inside?

Hi, you can create 2 entries for your my.servicename dns entry and clients should load balance the request between the dns entries. BUT it deepens on the client side to resend the request if the first node is down.

This works almost perfect with chrome and http request, but i’m not sure if sql client will do that.

Also can use dockerized keepalived to share a virtual ip between all nodes: https://github.com/osixia/docker-keepalived


1 Like

Hi @eldeberde

Finally, I configured an external haproxy+Keepalived to do high available the galera cluster

Thanks a lot for your reply

i am also trying to use the same haproxy/keepalived setup with docker swarm. Would you be kind enough to share how you configure your keepalived config? I am using AWS and I have some issues with the internal IP mapping setup…