Test
问题描述
我现在集群里有3太主机分别为163,192,193,现在假设193存在问题service的容器将不在193节点上运行。
[root@sit-cdpapp-163l ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ohjdhdzdiebk6ibjoriygfszu metabase193 Ready Active Reachable 19.03.5
tkoaoslrj2y526qugt3kwzfjo postgresql192 Ready Active Reachable 19.03.5
t8ixy0wk2mf1owvcsgu6bvt6b * sit-cdpapp-163l Ready Active Leader 19.03.5
解决方案
将3台node都打上标签来区分--163,192使用标签相同
[root@sit-cdpapp-163l ~]# docker node update --label-add tag=163 sit-cdpapp-163l
sit-cdpapp-163l
[root@postgresql192 certs.d]# docker node update --label-add tag=163 postgresql192
postgresql192
[root@metabase193 ~]# docker node update --label-add tag=193 metabase193
metabase193
[root@sit-cdpapp-163l ~]# docker service create --name worker --hostname worker --constraint 'node.labels.tag == 163' --network sk-net registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X
85mgnxhx5m3nwod5any3za1dj
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
[root@postgresql192 certs.d]# docker service scale worker=3
[root@sit-cdpapp-163l ~]# docker service ps worker
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
8xxlea1infyw worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X postgresql192 Running Running 5 minutes ago
92upe13xos13 \_ worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X postgresql192 Shutdown Failed 5 minutes ago "No such container: worker.1.9…"
ue5vpn47vl9x \_ worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X sit-cdpapp-163l Shutdown Shutdown 3 minutes ago
nu2w0uzulac3 worker.2 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X postgresql192 Running Running 4 minutes ago
hx5fjj9nilbb worker.3 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X sit-cdpapp-163l Running Running 21 seconds ago
Test2
测试update 替换指定service容器运行节点
[root@sit-cdpapp-163l ~]# docker service update --constraint-add 'node.labels.tag == 193' worker
worker
overall progress: 0 out of 3 tasks
1/3: no suitable node (scheduling constraints not satisfied on 3 nodes)
2/3:
3/3:
^COperation continuing in background.
Use `docker service ps worker` to check progress.
- 如果你在创建时候指定过服务约束,现在想换地方,更新的时候 constraint-rm 和 constraint-add 要同时执行,否则就崩了,还好是后台,也有先启再停的策略。
[root@sit-cdpapp-163l ~]# docker service update --constraint-rm 'node.labels.tag == 163' worker
worker
overall progress: 3 out of 3 tasks
1/3: running [==================================================>]
2/3: running [==================================================>]
3/3: running [==================================================>]
verify: Service converged
[root@sit-cdpapp-163l ~]# docker service update --constraint-add 'node.labels.tag == 193' worker
worker
overall progress: 3 out of 3 tasks
1/3: running [==================================================>]
2/3: running [==================================================>]
3/3: running [==================================================>]
verify: Service converged
[root@postgresql192 certs.d]# docker service ps worker
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
pqe7ffne9sx1 worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X metabase193 Running Running 28 minutes ago
j5zoqbqi837s \_ worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X Shutdown Pending 34 minutes ago "no suitable node (scheduling …"
zmleg7w6wiqs \_ worker.1 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X sit-cdpapp-163l Shutdown Shutdown 34 minutes ago
qxga9yumzlte worker.2 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X metabase193 Running Running 27 minutes ago
vevxy0pahkpp \_ worker.2 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X postgresql192 Shutdown Shutdown 27 minutes ago
nty6x648eixr worker.3 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X metabase193 Running Running 27 minutes ago
z18epvm2o2wf \_ worker.3 registry.xxxx.com/sk_pbms_worker_dev:alpha3.4.X postgresql192 Shutdown Shutdown 27 minutes ago
补充注意
- 不排除有人创建时 --constraint 使用了未标记的标签,如果这样的话service会显示running,current state显示pending不分配节点,这时如果任意一个节点标签设置了create时未标记的标签,容器将瞬间部署到其上。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。