简体   繁体   English

Docker Swarm - 扩展容器

[英]Docker Swarm - Scaling Containers

I have a Docker swarm Environment with 7 nodes(3 master and 4 Workers) I am trying to Deploy a Container and buy requirement is that at any point of time I need 2 instance of this container running but when I scale this the Container should be deployed to a different node than it is currently running.我有一个带有 7 个节点(3 个主节点和 4 个工作节点)的 Docker 群环境我正在尝试部署一个容器并购买要求是在任何时候我都需要运行这个容器的 2 个实例但是当我扩展它时,容器应该是部署到与当前运行不同的节点。

Ex: say one instance of the container is running in Node 4 and I scale to scale=2 it should run in any other node except for Node 4.例如:假设容器的一个实例在节点 4 中运行,并且我扩展到scale=2它应该在除节点 4 之外的任何其他节点中运行。

tried this but no luck:试过这个但没有运气:

deploy:
  mode: global
  placement:
    constraints:
      - node.labels.cloud.type == nodesforservice

We solved this issue with deployment preferences configuration (under Placement section).我们通过部署首选项配置(在放置部分下)解决了这个问题。 We set up node.labels.worker, on all our worker nodes.我们在所有工作节点上设置了 node.labels.worker。 We have 3 workers they have node.labels.worker = worker1, node.labels.worker = worker2 and node.labels.worker = worker3 labels set to each of them.我们有 3 个工作人员,他们为每个工作人员设置了 node.labels.worker = worker1、node.labels.worker = worker2 和 node.labels.worker = worker3 标签。 On the docker compose side then we configure it:在 docker compose 端,我们对其进行配置:

      placement:
        max_replicas_per_node: 2
        constraints:
          - node.role==worker
        preferences:
          - spread: node.labels.worker

Note this will not FORCE it always on the separate node, but if it is possible it will do so.请注意,这不会始终在单独的节点上强制它,但如果可能的话,它会这样做。 So it is not hard limit.所以这不是硬限制。 Beware of that.小心那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM