Search code examples
docker-swarm

Can manager node balance instead of nginx?


Currently I have simple setup nginx server that point to another server with running docker containerenter image description here

I want to move to docker swarm mode but I'm not sure that I understand it right. I want add cluster with 2 servers.1 manager one worker Do I have to set nginx to point to manager node that will balance? enter image description here Or manage node doesn't do balancing? And setup would be like that? enter image description here


Solution

  • Ok. First off, you are not really gaining anything by splitting the docker swarm into 2 nodes - Docker swarm uses raft consensus which requires a strict majority, which means that you need at least 3 nodes to achieve any kind of high availability. if you lose the manager node the worker node will de-schedule all its work anyway.

    So, you can run really small swarms (1 or 2 node) where high availability is not a concern. Just make both nodes managers, and don't try to isolate tasks onto workers only.

    Your minimum HA comes in with a 3 node swarm :- make all 3 nodes managers, and just schedule workloads on the managers. You can add worker nodes to this, once you have 2 or 3 worker nodes you can think about adding a constraint to your services to ensure they run on workers only.


    Docker swarms ingress routing ensures that an external service can connect to a published port on any swarm node, and it will be routed to a service task on some node.

    This means you can use docker swarm directly as its own load balancer, if you want to use an external load balancer, then you need to tell your service to publish its ports in host mode so that docker does not load balance that port, and use placement constraints and replicas to ensure that the service runs tasks on all your docker nodes. Then your external loadbalancer can load balance across the swarm nodes where the tasks are scheduled.