Docker Community Forums

Share and learn in the Docker community.

Scaling nginx on swarm mode with multiple nodes

Hi guys,

I have a 3 node setup, i scale nginx to 10 services, it scales successfull, i can see all nginx containers on 3 nodes.

When i request to nginx server for first time, ingress takes me to node2. Node 2 has 3 nginx containers, and my requests balances around this 3 containers. But other nodes and containers in them, doesnt get any request. When i change my ip, or request from another location, the request is running on other node, this is ok.

So i think, ingress balance the traffic by ip addr, but i couldnt find any documentation about that. This logic doesnt sense to me, because an attacker can send a a lot of requests from same ip and then the node which will handle requests will fail.

What you think about that ? I dont want to use any other load balancing software or nginx as load balancer, just testing ingress mode to understand deeply. Or should i have to use load balancer ?


Hi :slight_smile:

Do you start the containers with dnsrr as endpoint-mode?

Thanks @terpz,

I tried dnsrr mode but it returns “port published with ingress mode can’t be used with dnsrr mode” . Also, i read about modes and vip mode, it’s clear for me now. I totally missed that, thanks for reply.

But the problem still goes up. Since i cant publish ports in dnsrr mode, nginx doesnt responses. I tried some few solutions but doesnt works on swarm mode with multiple nodes.

All tutorials i found uses haproxy or nginx to load balance.
Also documentation says;

“DNS round-robin is useful in cases where you want to use your own load balancer”

Should i really use a load balancer for best practice ?

Well, you can… but only if you publish the port with ‘mode: host’. Honestly this type of settup makes most sense if you already have an external loadbalancer forwarding traffic to your nodes. This type of setup makes most sense for a cluster internal reverseproxy. Forward traffic to tasks.{servicename} (of course you need to replace {servicename} with the name of your service} and you should be good.

my point with the dnsrr was more, if you used it, docker wont loadbalance to different nodes, which could explain your issue