Docker Community Forums

Share and learn in the Docker community.

Docker swarm: load-balancer doesn't cycle through all tasks

swarm

(Adrianopinaffo) #1

I have 2 nodes in my swarm cluster, a manager and a worker. I deployed a stack with 5 replicas distributed in those nodes. The yaml file has a network called webnet for the service web. After they are deployed I try to access the service, but when I use the IP address of the manager node it load-balances between 2 replicas, and if I use the IP address of the worker it load-balances among the other 3 replicas. So, using only docker, how can I load-balance among all the 5 replicas?

My nodes:

root@debiancli:~/docker# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
5y256zrqwalq1hcxmqnnqc177     centostraining      Ready               Active                                  18.06.0-ce
mkg6ecl3x28uyyqx7gvzz0ja3 *   debiancli           Ready               Active              Leader              18.06.0-ce

Tasks in manager (self) and worker (centostraining):

root@debiancli:~/docker# docker node ps self
ID                  NAME                  IMAGE                              NODE                DESIRED STATE       CURRENT STATE         ERROR               PORTS
stbe721sstq7        getstartedlab_web.3   get-started:part2   debiancli           Running             Running 2 hours ago                       
6syjojjmyh0y        getstartedlab_web.5   get-started:part2   debiancli           Running             Running 2 hours ago                       
root@debiancli:~/docker# docker node ps centostraining 
ID                  NAME                  IMAGE                              NODE                DESIRED STATE       CURRENT STATE                    ERROR               PORTS
wpvsd98vfwd1        getstartedlab_web.1   get-started:part2   centostraining      Running             Running less than a second ago                       
e3z8xybuv53l        getstartedlab_web.2   get-started:part2   centostraining      Running             Running less than a second ago                       
sd0oi675c2am        getstartedlab_web.4   get-started:part2   centostraining      Running             Running less than a second ago

The stack and its tasks:

root@debiancli:~/docker# docker stack ls
NAME                SERVICES            ORCHESTRATOR
getstartedlab       1                   Swarm
root@debiancli:~/docker# docker stack ps getstartedlab 
ID                  NAME                  IMAGE                              NODE                DESIRED STATE       CURRENT STATE                    ERROR               PORTS
wpvsd98vfwd1        getstartedlab_web.1   get-started:part2   centostraining      Running             Running less than a second ago                       
e3z8xybuv53l        getstartedlab_web.2   get-started:part2   centostraining      Running             Running less than a second ago                       
stbe721sstq7        getstartedlab_web.3   get-started:part2   debiancli           Running             Running 2 hours ago                                  
sd0oi675c2am        getstartedlab_web.4   get-started:part2   centostraining      Running             Running less than a second ago                       
6syjojjmyh0y        getstartedlab_web.5   get-started:part2   debiancli           Running             Running 2 hours ago 

The networks (getstartedlab_webnet is used by my tasks)

root@debiancli:~/docker# docker network ls
NETWORK ID          NAME                   DRIVER              SCOPE
b95dd9ee2ae6        bridge                 bridge              local
63578897e920        docker_gwbridge        bridge              local
x47kwsfa23oo        getstartedlab_webnet   overlay             swarm
7f77ad495edd        host                   host                local
ip8czm66ofng        ingress                overlay             swarm
f2cc6118fde7        none                   null                local

docker-compose.yml used to deploy the stack:

root@debiancli:~/docker#cat docker-compose.yml 
version: "3"
services:
  web:
    image: get-started:part2
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "4000:80"
    networks:
      - webnet
networks:
  webnet:

Accessing the service from a third machine (this curl and grep pulls the container name)

[Ubuntu:~]$ debiancli=192.168.182.129
[Ubuntu:~]$ centostraining=192.168.182.133
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
f4c1e3ff53f2
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
de2110bee2f7
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
f4c1e3ff53f2
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
de2110bee2f7
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
f4c1e3ff53f2
[Ubuntu:~]$ curl -s $debiancli:4000 | grep -oP "(?<=</b> )[^<].{11}"
de2110bee2f7
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
72b757f92983
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
d2e824865436
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
b53c3fd0cfbb
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
72b757f92983
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
d2e824865436
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
b53c3fd0cfbb
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
72b757f92983
[Ubuntu:~]$ curl -s $centostraining:4000 | grep -oP "(?<=</b> )[^<].{11}"
d2e824865436

Notice that when I probe debiancli (swarm manager) it loops through containers f4c1e3ff53f2 and de2110bee2f7 only, that is, the 2 replicas running on the manager and the same happens for the 3 replicas in centostraining (swarm worker). So, what am I missing?