1.swarm
1.1swarm是什么
是docker官方推出的容器编排软件,可以对多台宿主机进行编排。
1.2swarm和compose
共同点:
都是docker官方推出的容器编排工具。
不同点
compose是使用python语言编写的,swarm几乎全部使用的Go语言编写。
compose只能对一台宿主机上的容器进行编排,swarm可以对多台宿主机的容器进行编排
2.Swarm集群部署
2.1布局
2.2manager节点创建swarm集群
[root@manager60 ~]# docker swarm init --advertise-addr 192.168.83.60
Swarm initialized: current node (zjwbvtrtysz9it26p2e7c285e) is now a manager.
To add a worker to this swarm, run the following command:
#下面这行是添加节点的方式,记得保存。
docker swarm join --token SWMTKN-1-1s10dzloer8adkbbglliay6qtplah6kf2sxl36zj91bjafnpj7-ajuy00nxif2bx7wl1aw9oxpo6 192.168.83.60:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[root@manager60 ~]#
2.2worker节点加入集群
[root@worker61 ~]# docker swarm join --token SWMTKN-1-1s10dzloer8adkbbglliay6qtplah6kf2sxl36zj91bjafnpj7-ajuy00nxif2bx7wl1aw9oxpo6 192.168.83.60:2377
[root@worker62 ~]# docker swarm join --token SWMTKN-1-1s10dzloer8adkbbglliay6qtplah6kf2sxl36zj91bjafnpj7-ajuy00nxif2bx7wl1aw9oxpo6 192.168.83.60:2377
2.3manager查看加入集群的节点
[root@manager60 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
zjwbvtrtysz9it26p2e7c285e * manager60 Ready Active Leader 20.10.13
fm7puk0c9zx49ap1dnamumr4p worker61 Ready Active 20.10.14
o81r9f2c8gaza9uwm74ufb5a0 worker62 Ready Active 20.10.14
[root@manager60 ~]#
2.4manager创建任务
docker service create --replicas 10 --name helloworld alpine ping docker.com
[root@manager60 ~]# docker service ps helloworld
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
nnjbvjv1xbwc helloworld.1 alpine:latest worker62 Running Running 25 seconds ago
yqxihet5qsuj helloworld.2 alpine:latest manager60 Running Running 22 seconds ago
kzhjj1kl7ecr helloworld.3 alpine:latest manager60 Running Running 21 seconds ago
pd82k2ho8fhj helloworld.4 alpine:latest worker62 Running Running 25 seconds ago
l4bxkdbbvd8l helloworld.5 alpine:latest worker61 Running Running 26 seconds ago
4ttd7btjm7uw helloworld.6 alpine:latest worker62 Running Running 26 seconds ago
in1jaii6qi1j helloworld.7 alpine:latest manager60 Running Running 22 seconds ago
1y1o4yjlc7vy helloworld.8 alpine:latest manager60 Running Running 22 seconds ago
sli6k8zec6yq helloworld.9 alpine:latest worker61 Running Running 26 seconds ago
5wwzc1i2se3x helloworld.10 alpine:latest worker61 Running Running 26 seconds ago
[root@manager60 ~]#
2.5改变容器数量
docker service scale helloworld=1 #容器数量收缩为1
docker service scale helloworld=10 #容器数量扩容为1
[root@manager60 ~]# docker service scale helloworld=1
helloworld scaled to 1
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
[root@manager60 ~]# docker service ps helloworld
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
nnjbvjv1xbwc helloworld.1 alpine:latest worker62 Running Running about a minute ago
[root@manager60 ~]#
[root@manager60 ~]# docker service scale helloworld=10
helloworld scaled to 10
overall progress: 10 out of 10 tasks
1/10: running
2/10: running
3/10: running
4/10: running
5/10: running
6/10: running
7/10: running
8/10: running
9/10: running
10/10: running
verify: Service converged
[root@manager60 ~]#
2.6节点退出集群
docker swarm leave -f
2.7swarm的manager和worker如何通信
2377端口 manager端口监听
7946 node之间通信
4789 容器overlay网络使用