docker swarm,服务任务未部署到新创建的swarm worker节点

时间:2018-06-29 09:47:59

标签: docker docker-swarm

已经有两个群集节点:myvm1myvm2

这是我的服务和任务,它们已经部署到myvm1myvm2节点上。

☁  docker-research [master] ⚡  docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                        PORTS
pwjxzu80q1vx        getstartedlab_web   replicated          5/5                 novaline/get-started:part2   *:4000->80/tcp
☁  docker-research [master] ⚡  docker service ps getstartedlab_web
ID                  NAME                  IMAGE                        NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
32c88logpvar        getstartedlab_web.1   novaline/get-started:part2   myvm2               Running             Running 3 hours ago
3lpx3gotggi8        getstartedlab_web.2   novaline/get-started:part2   myvm1               Running             Running 3 hours ago
meuwm1dhxeba        getstartedlab_web.3   novaline/get-started:part2   myvm2               Running             Running 3 hours ago
jrxs9xbjxz56        getstartedlab_web.4   novaline/get-started:part2   myvm1               Running             Running 33 minutes ago
oocrasndz98s        getstartedlab_web.5   novaline/get-started:part2   myvm1               Running             Running 33 minutes ago

现在,我想添加一个新的swarm worker节点-myvm3

这是我的步骤:

创建新VM-myvm3

docker-machine create -d virtualbox myvm3

myvm3添加为一个工作节点:

☁  docker-research [master] ⚡  docker-machine ssh myvm3 'docker swarm join --token SWMTKN-1-002x9ve85tv0jpodgd0y1244itb2knyr3b6j4qn6qiepl7yjx7-4p08k808lz9eqtqu1szdki3md 192.168.99.100:2377'
This node joined a swarm as a worker.

检查群节点:

☁  docker-research [master] ⚡  docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
qciplvmrh6j758hs8mi8jyqdz *   myvm1               Ready               Active              Leader              18.05.0-ce
5xxrbayq0n0068awdctneyifg     myvm2               Ready               Active                                  18.05.0-ce
gfuc93zs1k45evlhlxqfd2qo9     myvm3               Ready               Active                                  18.05.0-ce

再次部署:

☁  docker-research [master] ⚡  docker stack deploy getstartedlab -c ./get-started-v2/docker-compose.yml
Updating service getstartedlab_web (id: pwjxzu80q1vxejc3d3hzoc89l)

现在,我认为服务任务将部署到三个节点-myvm1myvm2myvm3。但是,当我再次检查任务状态时,任务仍部署在myvm1myvm2节点中。

☁  docker-research [master] ⚡  docker service ps getstartedlab_web
ID                  NAME                  IMAGE                        NODE                DESIRED STATE       CURRENT STATE               ERROR               PORTS
32c88logpvar        getstartedlab_web.1   novaline/get-started:part2   myvm2               Running             Running 4 hours ago
3lpx3gotggi8        getstartedlab_web.2   novaline/get-started:part2   myvm1               Running             Running 4 hours ago
meuwm1dhxeba        getstartedlab_web.3   novaline/get-started:part2   myvm2               Running             Running 4 hours ago
jrxs9xbjxz56        getstartedlab_web.4   novaline/get-started:part2   myvm1               Running             Running about an hour ago
oocrasndz98s        getstartedlab_web.5   novaline/get-started:part2   myvm1               Running             Running about an hour ago

如果要在所有节点中部署服务怎么办?

1 个答案:

答案 0 :(得分:0)

您必须将服务部署为全局模式,一旦新节点可用,调度程序就会在所有可用节点上放置一个任务。添加方式:全局,如下所示,在撰写文件中的deploy标签中(以粗体突出显示)。它应该在所有可用节点上创建任务。希望这会有所帮助。

服务:  flask-app:     图片:127.0.0.1:5003/flask-app:latest     建立:。     取决于:       -flask-mysql     命令:python3 /opt/app.py     端口:       -“ 5001:5000”     网络:       -覆盖     部署:       模式:全局