从零开始入门 K8s | 调度器的调度流程和算法介绍(12)


-- 描述符合条件的一组 Pod 在指定 TopologyKey 上的打散要求 。

下面我们来看一下怎么描述一组 Pod , 如下图所示:

spec:
 topologySpreadConstraints:
 - maxSkew: 1
   whenUnsatisfiable: DoNotSchedule
   topologyKey: k8s.io/hostname
   selector:
     matchLabels:
       app: foo
     matchExpressions:
     - key: app
       operator: In
       values: ['foo' 'foo2'

topologySpreadConstraints: 用于描述 Pod 要在什么拓扑结构上进行均衡打散 , 多个 topologySpreadConstraint 之间是 and 关系;selector:用于描述需要满足的拓扑打散的一组 Pod 的列表topologyKey: 作用在什么拓扑结构上;maxSkew: 最大允许的不均衡数量;whenUnsatisfiable: 当不满足 topologySpreadConstraint 的时候的策略 , DoNotSchedule:表示作用于 filter 阶段 , ScheduleAnyway:作用于 score 阶段 。 下面举例描述下:

推荐阅读