Docker Swarm集群实践——管理篇

本文介绍了Docker Swarm集群的管理,包括调度策略(random, spread, binpack)及其设置,以及过滤器的使用:约束(constraint)、健康检查(health)、亲和性(affinity)、依赖(dependency)和端口(port)。通过过滤条件,可以自定义容器部署位置,避免端口冲突,确保集群资源有效利用。" 105157147,9331514,Python爬虫实战:利用selenium模拟京东登录,"['爬虫技术', 'selenium', '浏览器自动化']
摘要由CSDN通过智能技术生成

前面我们已经部署好了一个Docker Swarm集群环境,接下来,我们就对Swarm集群的相关管理进行简单介绍。


集群调度策略

既然是集群,就是有一个调度策略,也就是该集群包含那么多子节点,我到底是设置一个什么样的策略来进行分配呢?


我们查看Docker官方文档可以看到Swarm的集群调度包含三种策略:

To choose a ranking strategy, pass the --strategy flag and a strategy value to the swarm manage command. Swarm currently supports these values:

  • spread
  • binpack
  • random

The spread and binpack strategies compute rank according to a node’s available CPU, its RAM, and the number of containers it has. The random strategy uses no computation. It selects a node at random and is primarily intended for debugging.

Your goal in choosing a strategy is to best optimize your cluster according to your company’s needs.

Under the spread strategy, Swarm optimizes for the node with the least number of containers. The binpack strategy causes Swarm to optimize for the node which is most packed. Note that a container occupies resource during its life cycle, including exited state. Users should be aware of this condition to schedule containers. For example, spread strategy only checks number of containers disregarding their states. A node with no active containers but high number of stopped containers may not be selected, defeating the purpose of load sharing. User could either remove stopped containers, or start stopped containers to achieve load spreading. The random strategy, like it sounds, chooses nodes at random regardless of their available CPU or RAM.

Using the spread strategy results in containers spread thinly over many machines. The advantage of this strategy is that if a node goes down you only lose a few containers.

The binpack strategy avoids fragmentation because it leaves room for bigger containers on unused machines. The strategic advantage of binpack is that you use fewer machines as Swarm tries to pack as many containers as it can on a node.

简单总结一下:

  • random策略:随机选择节点。一般用于开发测试阶段。
  • spread策略:默认策略,swarm优先选择占用资源(如CPU、内存等)最少的节点,能保证集群中所有节点资源的均匀使用。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值