最近更新时间:2024.01.19 14:39:11
首次发布时间:2023.07.20 10:49:31
部署策略是资源跨集群分发的基础,可用于指定资源部署在哪些集群中。本文介绍如何使用 Yaml 创建部署策略。
以创建命名空间级别的部署策略为例,完整的 Yaml 模板如下:
apiVersion: core.kubeadmiral.io/v1alpha1 kind: PropagationPolicy metadata: name: mypolicy # adjust name for your policy namespace: users-namespace # specify your namespace to apply policy spec: schedulingMode: Duplicate # schedulingMode could be Divide or Duplicate disableFollowerScheduling: false placement: - cluster: ClusterID-01 # Modify the selected cluster ID to propagate the resource. #preferences: #weight: 40 #minReplicas: 1 #maxReplicas: 3 - cluster: ClusterID-02 # Modify the selected cluster ID to propagate the resource. #preferences: #weight: 40 #minReplicas: 1 #maxReplicas: 3 #clusterSelector: #region: beijing #az: zone1 #clusterAffinity: #- matchExpressions: #- key: region #operator: In #values: #- beijing #- key: provider #operator: In #values: #- volcengine #tolerations: #- key: "key1" #operator: "Equal" #value: "value1" #effect: "NoSchedule" #- key: "key2" #operator: "Exists" #effect: "NoSchedule" #maxClusters: 1 # Maximum number of clusters that can be scheduled. reschedulePolicy: disableRescheduling: false rescheduleWhen: policyContentChanged: true clusterJoined: false clusterLabelsChanged: false clusterAPIResourcesChanged: false replicaRescheduling: avoidDisruption: true # If set to true, the algorithm will attempt to avoid disrupting existing replicas (this might lead to deviation from weights). autoMigration: keepUnschedulableReplicas: true # If set to true, besides starting new pods, the unschedulable pods will be kept in the original cluster so the new pods can be migrated back if the cluster recovers. when: podUnschedulableFor: 1m # pods which remain unschedulable beyond this duration will be subject to auto migration.
配置项 | 说明 |
---|---|
apiVersion | API 版本信息,固定为:core.kubeadmiral.io/v1alpha1 。 |
kind | 部署策略的级别,包括:PropagationPolicy、ClusterPropagationPolicy。
|
name | 自定义部署策略的名称。 |
namespace | 命名空间级别部署策略所属的命名空间,当kind 选择PropagationPolicy 时需要配置,直接指定已有命名空间的名称即可。 |
schedulingMode | 副本调度策略,包括: Duplicate、Divide。
说明 副本模式调度目前仅针对 Deployment 资源生效,其他资源默认按照复制分发生效。 |
disableFollowerScheduling | 跟随调度,工作负载关联的资源(如 ConfigMap、Secret等)自动跟随副本分发到成员集群中。
|
replicasStrategy | 集群优先级配置参数, |
placement | 指定集群:部署策略只在指定的成员集群内生效,资源仅在指定成员集群中进行调度。推荐选择多个成员集群作为部署集群,以满足联邦调度的场景。 说明
配置资源分发的集群、权重、副本数,适用于多集群分发的场景。配置参数包括:cluster、weight、minReplicas、maxReplicas。
典型应用场景如下:
|
clusterSelector | clusterSelector 集群标签:通过键值对形式的标签来匹配集群。部署策略在 clusterSelector 标签匹配的成员集群内生效,资源在 clusterSelector 匹配标签的成员集群中进行调度。 说明 控制台要求选择一种类型的集群标签进行配置,若同时配置多个标签,生效规则如下:
|
clusterAffinity | clusterAffinity 集群标签:通过强制调度条件中配置的选择器标签来匹配集群。部署策略在 clusterAffinity 标签匹配的成员集群内生效,资源仅在 clusterAffinity 匹配标签的成员集群中进行调度。 说明 控制台要求选择一种类型的集群标签进行配置,若同时配置多个标签,生效规则如下:
|
tolerations | 集群污点调度功能,配置后可按需配置污点容忍,并按照选择的多个污点进行集群调度。示例如下:
|
maxClusters | 副本分发的最大集群数,可用于配置资源可调度到的成员集群数上限,取值范围为正整数。 |
disableRescheduling | 关闭重调度功能的总开关,配置为 false 表示开启重调度功能。
|
rescheduleWhen | 启用重调度机制下,可指定触发重调度的条件,当条件发生时会自动触发资源按照最新的策略配置及集群环境重新调度。
|
avoidDisruption | 默认开启。开启后,因扩缩容、策略更新、副本不可调度迁移等原因导致副本重分配时,不会影响当前已调度的副本。
|
示例一:副本数不变场景
| |
示例二:扩容场景
| |
示例三:缩容场景
| |
autoMigration | 副本不可调度迁移功能,需要配置以下参数:podUnschedulableFor、keepUnschedulableReplicas
|
完成创建部署策略后,可在进行资源分发时,直接引用部署策略,从而实现与预期相符的资源分发。详细介绍参见:资源分发实践。