Docker swarm cluster construction

Qilin 01 2022-01-15 03:25:17 阅读数:412

docker swarm cluster construction

There are three hosts in total
192.168.19.4
192.168.19.5
192.168.19.6

192.168.19.4
Set host name

[[email protected] redis-cluster]# hostnamectl set-hostname manager
[[email protected] redis-cluster]#

initialization swarm colony

[[email protected] redis-cluster]# docker swarm init 
Swarm initialized: current node (lfjk87d0pguk7tkgoj69fu9nq) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-adqinc1qrub0uyti0683hjqvw 192.168.19.4:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Get join token

[[email protected] redis-cluster]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-b1r2kkd4ccic3jpdlpsh8sjlq 192.168.19.4:2377
[[email protected] redis-cluster]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-adqinc1qrub0uyti0683hjqvw 192.168.19.4:2377
[[email protected] redis-cluster]# 

Query all nodes of the cluster

[[email protected] redis-cluster]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lfjk87d0pguk7tkgoj69fu9nq * manager Ready Active Leader 20.10.11

192.168.19.5
Set machine name

[[email protected] ~]# hostnamectl set-hostname worker

To join the cluster

[[email protected] ~]# docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-adqinc1qrub0uyti0683hjqvw 192.168.19.4:2377
This node joined a swarm as a worker.

192.168.19.4
Create services

[[email protected] redis-cluster]# docker service create --replicas 1 --name mynginx -p 80:80 nginx
puajwi3kllcgd482vdyqdm4mn
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converge

View service

[[email protected] redis-cluster]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
puajwi3kllcg mynginx replicated 1/1 nginx:latest *:80->80/tcp
[[email protected] redis-cluster]# docker service inspect --pretty mynginx
ID: yirs931yqmkzwjkuhhlrvyex3
Name: mynginx
Service Mode: Replicated
Replicas: 1
Placement:
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order: stop-first
RollbackConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Rollback order: stop-first
ContainerSpec:
Image: nginx:[email protected]:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
Init: false
Resources:
Endpoint Mode: vip
Ports:
PublishedPort = 80
Protocol = tcp
TargetPort = 80
PublishMode = ingress

Dynamic capacity

[[email protected] redis-cluster]# docker service scale mynginx=2
mynginx scaled to 2
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
[[email protected] redis-cluster]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
puajwi3kllcg mynginx replicated 2/2 nginx:latest *:80->80/tcp

see 192.168.19.4 machine

[[email protected] redis-cluster]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe5299cd8172 nginx:latest "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 80/tcp mynginx.1.4d3c535tl0jid28z5i54info9
5ae1db544afc redis "docker-entrypoint.s…" 29 minutes ago Exited (0) 27 minutes ago redis-6372

see 192.168.19.5 machine

[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d7aa8a46a8c nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp mynginx.2.jqpo0xtpdo6usuavhmiptu0py

It's all deployed nginx

The viewing service runs on that machine Be careful : Only in manage Node usage

[[email protected] redis-cluster]# docker service ps mynginx
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
4d3c535tl0ji mynginx.1 nginx:latest manager Running Running 12 minutes ago
jqpo0xtpdo6u mynginx.2 nginx:latest worker Running Running 6 minutes ago

Service application rolling update

[[email protected] redis-cluster]# docker service update --replicas 2 --update-delay 10s mynginx
mynginx
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged

Be careful :

  1. manager Node cannot join ; Just turn off the firewall of the machine
版权声明:本文为[Qilin 01]所创,转载请带上原文链接,感谢。 https://javamana.com/2021/12/202112122306442971.html