docker swarm 當 leader掛了強制選出集群leader

今天在試玩 docker swarm 當 leader掛了,整個集群無法進行時怎麼辦?

Error response from daemon: rpc error: code = Unknown desc = The swarm does not have a leader. It’s possible that too few managers are online. Make sure more than half of the managers are online.

一般來說只要集群重新選出新的 leader 即可,可透過下列指令強制選出

# docker swarm init --force-new-cluster


[root@docker2 _data]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
pz2yv07xlmo7hob2j6foyzk9q docker1.example.com Unknown Active 18.06.1-ce
qmcbq33t8lbj12nlvg8p6mwrm * docker2.example.com Ready Active Leader 18.06.1-ce
[root@docker2 _data]# 
ID                            HOSTNAME              STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pz2yv07xlmo7hob2j6foyzk9q     docker1.example.com   Down                Active                                  18.06.1-ce
qmcbq33t8lbj12nlvg8p6mwrm *   docker2.example.com   Ready               Active              Leader              18.06.1-ce
[root@docker2 _data]# docker node ls

ID                  NAME                IMAGE               NODE                  DESIRED STATE       CURRENT STATE            ERROR                              PORTS
mg8vrfv8xhs1        nginx.1             nginx:latest        docker2.example.com   Running             Running 5 minutes ago                                       
oeyje9bdptbz         \_ nginx.1         nginx:latest        docker1.example.com   Shutdown            Running 12 minutes ago                                      
a3hqc1i02tns        nginx.2             nginx:latest        docker2.example.com   Running             Running 6 minutes ago                                       
t8fkoubpm876         \_ nginx.2         nginx:latest        docker2.example.com   Shutdown            Failed 6 minutes ago     "No such container: nginx.2.t8…"   
[root@docker2 _data]#

 

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.