# High availability on SWARM

**URL:** <https://forums.docker.com/t/high-availability-on-swarm/49761>\
**Category:** Swarm\
**Created:** [April 21, 2018, 5:58pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761 "2018-04-21T17:58:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![itdep](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@itdep](https://forums.docker.com/u/itdep)\
**Post date:** [April 21, 2018, 5:58pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/1 "2018-04-21T17:58:31Z")

</div>

Hello

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

---

<div class="post-metadata">

**Author:** ![trajano](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/trajano/32/16038_2.png) [@trajano](https://forums.docker.com/u/trajano)\
**Post date:** [April 22, 2018, 2:59pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/2 "2018-04-22T14:59:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![itdep](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@itdep](https://forums.docker.com/u/itdep)\
**Post date:** [April 23, 2018, 12:44pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/3 "2018-04-23T12:44:04Z")

</div>

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?

 ![structure](https://global.discourse-cdn.com/docker/original/3X/9/c/9cb999df7e602778fade8c2ff5b36bd75e30e044.PNG)

---

<div class="post-metadata">

**Author:** ![trajano](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/trajano/32/16038_2.png) [@trajano](https://forums.docker.com/u/trajano)\
**Post date:** [April 23, 2018, 10:29pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/4 "2018-04-23T22:29:12Z")

</div>

> [@itdep](#):
>
> Do you refer to exposing ports with -P option?

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

---

<div class="post-metadata">

**Author:** ![nikolashermann](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/nikolashermann/32/12664_2.png) [@nikolashermann](https://forums.docker.com/u/nikolashermann)\
**Post date:** [April 25, 2018, 7:24am UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/5 "2018-04-25T07:24:27Z")

</div>

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/](https://docs.docker.com/engine/swarm/ingress/)

---

<div class="post-metadata">

**Author:** ![itdep](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@itdep](https://forums.docker.com/u/itdep)\
**Post date:** [April 25, 2018, 1:12pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/6 "2018-04-25T13:12:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eldeberde](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@eldeberde](https://forums.docker.com/u/eldeberde)\
**Post date:** [April 25, 2018, 1:32pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/7 "2018-04-25T13:32:56Z")

</div>

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](https://github.com/osixia/docker-keepalived)

Regards

---

<div class="post-metadata">

**Author:** ![itdep](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@itdep](https://forums.docker.com/u/itdep)\
**Post date:** [July 3, 2018, 11:07am UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/8 "2018-07-03T11:07:03Z")

</div>

Hi @eldeberde

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

Thanks a lot for your reply

---

<div class="post-metadata">

**Author:** ![jedivpn](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jedivpn](https://forums.docker.com/u/jedivpn)\
**Post date:** [March 3, 2019, 10:47pm UTC](https://forums.docker.com/t/high-availability-on-swarm/49761/9 "2019-03-03T22:47:50Z")

</div>

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…
