这个题目是不是很奇怪,没错!所谓的负载再平衡,指的是:当集群新加入某个节点,或者某个节点由于异常离开集群,之后又加回到集群的情况。
很显然,这些新的节点上是不会有负载的,也就是没有task运行的,如果想要这些节点上也有task,就需要对service执行再平衡的操作,看下面的这个例子:
目前集群中3个节点
[root@nccztsjb-node-01 ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION gxfkhuc95br6ltkhorpw1q4tq * nccztsjb-node-01 Ready Active Reachable 20.10.17 7d59usghrgq05k0yh4lbykw5v nccztsjb-node-04 Ready Active Reachable 20.10.17 wnd24l698iruhhp1xw0y3iyig nccztsjb-node-05 Ready Active Leader 20.10.17 [root@nccztsjb-node-01 ~]#
运行一个service的5个task
[root@nccztsjb-node-01 ~]# docker service ps nginx_sec | grep Running xrij4n1qqcu4 nginx_sec.1 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-04 Running Running 5 minutes ago v5b6c7zu2gmp nginx_sec.2 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-05 Running Running 3 minutes ago ysej3ewyle34 nginx_sec.3 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-05 Running Running 3 minutes ago tbajdc0zz4bm nginx_sec.4 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-04 Running Running 3 minutes ago reueygzaldds nginx_sec.5 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-01 Running Running 3 minutes ago [root@nccztsjb-node-01 ~]#
task在不同的节点上运行着。
新加入一个节点
[root@nccztsjb-node-01 ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION gxfkhuc95br6ltkhorpw1q4tq * nccztsjb-node-01 Ready Active Reachable 20.10.17 lxjosziajpbl7jt04aycdnklr nccztsjb-node-02 Ready Active 20.10.17 7d59usghrgq05k0yh4lbykw5v nccztsjb-node-04 Ready Active Reachable 20.10.17 wnd24l698iruhhp1xw0y3iyig nccztsjb-node-05 Ready Active Leader 20.10.17 [root@nccztsjb-node-01 ~]#
新加入节点之后,这个节点上是不会有task运行的
为了让这个节点有task运行,可以使用再平衡(滚动升级的功能),使用 --force 选项
docker service update --force nginx_sec
[root@nccztsjb-node-01 ~]# docker service update --force nginx_sec nginx_sec overall progress: 5 out of 5 tasks 1/5: running [==================================================>] 2/5: running [==================================================>] 3/5: running [==================================================>] 4/5: running [==================================================>] 5/5: running [==================================================>] verify: Service converged [root@nccztsjb-node-01 ~]#
再次查看task的运行情况
[root@nccztsjb-node-01 ~]# docker service ps nginx_sec | grep Running pu77ic1y6h3a nginx_sec.1 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-02 Running Running 31 seconds ago gg7iq7oc8dom nginx_sec.2 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-05 Running Running 26 seconds ago lw16tb2o0ttq nginx_sec.3 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-04 Running Running 33 seconds ago qg3kmiy5qpko nginx_sec.4 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-02 Running Running 35 seconds ago ikle3qlqlm0a nginx_sec.5 172.20.58.152/middleware/nginx:1.21.4 nccztsjb-node-01 Running Running 29 seconds ago [root@nccztsjb-node-01 ~]#
这个节点都有task运行了!
警告!
这个纯粹是在极端情况下的负载再平衡的测试。
一般不会用到,原因是,新加节点没有task运行很正常,带重启、更新、升级也会自然进行再平衡的操作。
为了再平衡而执行再平衡的操作,会切断终端用户对服务的访问。
标签:node,负载,01,service,nginx,swarm,Running,nccztsjb,root From: https://www.cnblogs.com/chuanzhang053/p/16813242.html