Search code examples
dockerload-balancingdocker-swarm

Round Robin Behaviour of Docker SWARM container not working across multiple hosts


If a swarm service is deployed in a 2 node cluster (1manager+1worker). Assuming the replicas is set to 3, then containers will be launched: 2 in one node and 1 in the other node.

When the curl command is hit on IP address manager or worker - the container residing on the same host are being served in an RR manner. The request does not get served from the other node, hence the purpose of failover or HA (across multiple nodes ) is not being achieved by this configuration for me.

Let me share you the detailed steps that I have done: https://privatedock.wordpress.com/2017/04/09/docker-swarm/

Kindly let me know if I missed something. Thanks in advance.


Solution

  • I see you're deploying in AWS and using the Public IP for Swarm advertise IP. Are you sure you want to do this? AWS network charges are based on data flowing through the public IP. Have you opened up your firewall rules for your public interface?

    Port 7946 TCP/UDP for container network discovery.
    Port 4789 UDP for the container overlay network.
    

    You can rule out firewall if you used private IP addresses within your VPC. And you won't get charged for bandwidth.

    Your service was also created using VIP for load balancing. If you wanted DNS RR, you'd need to add --endpoint-mode dnsrr to your docker service create command.

    You can verify that DNS RR is working if you run the following python script in your containers. Replace SERVICE_NAME with the service you'd want to resolve against.

    python -c "import socket; print socket.gethostbyname_ex('SERVICE_NAME')[2]"