我的集群中有2个节点,一个管理器和一个工作器。我部署了一个堆栈,在这些节点中分布有5个副本。 yaml文件具有一个称为Web的网络,用于服务Web。部署它们后,我尝试访问该服务,但是当我使用管理器节点的IP地址时,它将在2个副本之间进行负载平衡;如果使用工作服务器的IP地址,则将在其他3个副本之间进行负载平衡。因此,仅使用docker,如何在所有5个副本之间进行负载平衡?
我的节点:
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
经理(自己)和工人(中心培训)中的任务:
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
堆栈及其任务:
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
网络(我的任务使用的是getstartedlab_webnet)
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用于部署堆栈:
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:
从第三台计算机访问服务(此curl和grep将拉出容器名称)
[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
请注意,当我探测debiancli(群发管理器)时,它仅循环遍历容器f4c1e3ff53f2
和de2110bee2f7
,也就是说,在管理器上运行的2个副本和在中心集中的3个副本都发生了同样的情况(勤劳的工人)。所以,我想念什么?