This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.3.2.3. 修改调度程序策略
您可以通过在 openshift-config
项目中创建或编辑调度程序策略配置映射来更改调度行为。在配置映射中添加和移除 predicates 和 priorities,以创建 调度程序策略。
流程
要修改当前的自定义调度,请使用以下方法之一:
编辑调度程序策略配置映射:
oc edit configmap <configmap-name> -n openshift-config
$ oc edit configmap <configmap-name> -n openshift-config
Copy to Clipboard Copied! 例如:
oc edit configmap scheduler-policy -n openshift-config
$ oc edit configmap scheduler-policy -n openshift-config
Copy to Clipboard Copied! 输出示例
apiVersion: v1 data: policy.cfg: | { "kind" : "Policy", "apiVersion" : "v1", "predicates" : [ {"name" : "MaxGCEPDVolumeCount"}, {"name" : "GeneralPredicates"}, {"name" : "MaxAzureDiskVolumeCount"}, {"name" : "MaxCSIVolumeCountPred"}, {"name" : "CheckVolumeBinding"}, {"name" : "MaxEBSVolumeCount"}, {"name" : "MatchInterPodAffinity"}, {"name" : "CheckNodeUnschedulable"}, {"name" : "NoDiskConflict"}, {"name" : "NoVolumeZoneConflict"}, {"name" : "PodToleratesNodeTaints"} ], "priorities" : [ {"name" : "LeastRequestedPriority", "weight" : 1}, {"name" : "BalancedResourceAllocation", "weight" : 1}, {"name" : "ServiceSpreadingPriority", "weight" : 1}, {"name" : "NodePreferAvoidPodsPriority", "weight" : 1}, {"name" : "NodeAffinityPriority", "weight" : 1}, {"name" : "TaintTolerationPriority", "weight" : 1}, {"name" : "ImageLocalityPriority", "weight" : 1}, {"name" : "SelectorSpreadPriority", "weight" : 1}, {"name" : "InterPodAffinityPriority", "weight" : 1}, {"name" : "EqualPriority", "weight" : 1} ] } kind: ConfigMap metadata: creationTimestamp: "2019-09-17T17:44:19Z" name: scheduler-policy namespace: openshift-config resourceVersion: "15370" selfLink: /api/v1/namespaces/openshift-config/configmaps/scheduler-policy
apiVersion: v1 data: policy.cfg: | { "kind" : "Policy", "apiVersion" : "v1", "predicates" : [
1 {"name" : "MaxGCEPDVolumeCount"}, {"name" : "GeneralPredicates"}, {"name" : "MaxAzureDiskVolumeCount"}, {"name" : "MaxCSIVolumeCountPred"}, {"name" : "CheckVolumeBinding"}, {"name" : "MaxEBSVolumeCount"}, {"name" : "MatchInterPodAffinity"}, {"name" : "CheckNodeUnschedulable"}, {"name" : "NoDiskConflict"}, {"name" : "NoVolumeZoneConflict"}, {"name" : "PodToleratesNodeTaints"} ], "priorities" : [
2 {"name" : "LeastRequestedPriority", "weight" : 1}, {"name" : "BalancedResourceAllocation", "weight" : 1}, {"name" : "ServiceSpreadingPriority", "weight" : 1}, {"name" : "NodePreferAvoidPodsPriority", "weight" : 1}, {"name" : "NodeAffinityPriority", "weight" : 1}, {"name" : "TaintTolerationPriority", "weight" : 1}, {"name" : "ImageLocalityPriority", "weight" : 1}, {"name" : "SelectorSpreadPriority", "weight" : 1}, {"name" : "InterPodAffinityPriority", "weight" : 1}, {"name" : "EqualPriority", "weight" : 1} ] } kind: ConfigMap metadata: creationTimestamp: "2019-09-17T17:44:19Z" name: scheduler-policy namespace: openshift-config resourceVersion: "15370" selfLink: /api/v1/namespaces/openshift-config/configmaps/scheduler-policy
Copy to Clipboard Copied! 调度程序需要几分钟时间来使用更新后的策略重启 pod。
更改所用的 predicates 和 priorities:
删除调度程序策略配置映射:
oc delete configmap -n openshift-config <name>
$ oc delete configmap -n openshift-config <name>
Copy to Clipboard Copied! 例如:
oc delete configmap -n openshift-config scheduler-policy
$ oc delete configmap -n openshift-config scheduler-policy
Copy to Clipboard Copied! 根据需要,编辑
policy.cfg
文件来添加和移除 policies 和 predicates。例如:
vi policy.cfg
$ vi policy.cfg
Copy to Clipboard Copied! 输出示例
apiVersion: v1 data: policy.cfg: | { "kind" : "Policy", "apiVersion" : "v1", "predicates" : [ {"name" : "MaxGCEPDVolumeCount"}, {"name" : "GeneralPredicates"}, {"name" : "MaxAzureDiskVolumeCount"}, {"name" : "MaxCSIVolumeCountPred"}, {"name" : "CheckVolumeBinding"}, {"name" : "MaxEBSVolumeCount"}, {"name" : "MatchInterPodAffinity"}, {"name" : "CheckNodeUnschedulable"}, {"name" : "NoDiskConflict"}, {"name" : "NoVolumeZoneConflict"}, {"name" : "PodToleratesNodeTaints"} ], "priorities" : [ {"name" : "LeastRequestedPriority", "weight" : 1}, {"name" : "BalancedResourceAllocation", "weight" : 1}, {"name" : "ServiceSpreadingPriority", "weight" : 1}, {"name" : "NodePreferAvoidPodsPriority", "weight" : 1}, {"name" : "NodeAffinityPriority", "weight" : 1}, {"name" : "TaintTolerationPriority", "weight" : 1}, {"name" : "ImageLocalityPriority", "weight" : 1}, {"name" : "SelectorSpreadPriority", "weight" : 1}, {"name" : "InterPodAffinityPriority", "weight" : 1}, {"name" : "EqualPriority", "weight" : 1} ] }
apiVersion: v1 data: policy.cfg: | { "kind" : "Policy", "apiVersion" : "v1", "predicates" : [ {"name" : "MaxGCEPDVolumeCount"}, {"name" : "GeneralPredicates"}, {"name" : "MaxAzureDiskVolumeCount"}, {"name" : "MaxCSIVolumeCountPred"}, {"name" : "CheckVolumeBinding"}, {"name" : "MaxEBSVolumeCount"}, {"name" : "MatchInterPodAffinity"}, {"name" : "CheckNodeUnschedulable"}, {"name" : "NoDiskConflict"}, {"name" : "NoVolumeZoneConflict"}, {"name" : "PodToleratesNodeTaints"} ], "priorities" : [ {"name" : "LeastRequestedPriority", "weight" : 1}, {"name" : "BalancedResourceAllocation", "weight" : 1}, {"name" : "ServiceSpreadingPriority", "weight" : 1}, {"name" : "NodePreferAvoidPodsPriority", "weight" : 1}, {"name" : "NodeAffinityPriority", "weight" : 1}, {"name" : "TaintTolerationPriority", "weight" : 1}, {"name" : "ImageLocalityPriority", "weight" : 1}, {"name" : "SelectorSpreadPriority", "weight" : 1}, {"name" : "InterPodAffinityPriority", "weight" : 1}, {"name" : "EqualPriority", "weight" : 1} ] }
Copy to Clipboard Copied! 根据调度程序 JSON 文件重新创建调度程序策略配置映射:
oc create configmap -n openshift-config --from-file=policy.cfg <configmap-name>
$ oc create configmap -n openshift-config --from-file=policy.cfg <configmap-name>
1 Copy to Clipboard Copied! - 1
- 输入配置映射的名称。
例如:
oc create configmap -n openshift-config --from-file=policy.cfg scheduler-policy
$ oc create configmap -n openshift-config --from-file=policy.cfg scheduler-policy
Copy to Clipboard Copied! 输出示例
configmap/scheduler-policy created
configmap/scheduler-policy created
Copy to Clipboard Copied!
3.2.3.1. 了解调度程序 predicates
predicates 是用于过滤掉不合格节点的规则。
OpenShift Container Platform 中默认提供一些 predicates。其中的一些 predicates 可以通过提供特定参数来自定义。可以组合多个 predicates 来提供更多节点过滤。
3.2.3.1.1. 静态 predicates
此类 predicates 不接受任何来自于用户的配置参数或输入。它们通过其确切的名称在调度程序配置中指定。
3.2.3.1.1.1. 默认 predicates
默认的调度程序策略包括以下 predicates:
NoVolumeZoneConflict
predicate 检查区中是否有 pod 请求的卷。
{"name" : "NoVolumeZoneConflict"}
{"name" : "NoVolumeZoneConflict"}
MaxEBSVolumeCount
predicate 检查可附加到 AWS 实例的最大卷数量。
{"name" : "MaxEBSVolumeCount"}
{"name" : "MaxEBSVolumeCount"}
MaxAzureDiskVolumeCount
predicate 会检查 Azure 磁盘卷的最大数量。
{"name" : "MaxAzureDiskVolumeCount"}
{"name" : "MaxAzureDiskVolumeCount"}
PodToleratesNodeTaints
predicate 检查 pod 是否可以容忍节点污点。
{"name" : "PodToleratesNodeTaints"}
{"name" : "PodToleratesNodeTaints"}
CheckNodeUnschedulable
predicate 会检查 pod 是否可以调度到具有 Unschedulable
规格的节点。
{"name" : "CheckNodeUnschedulable"}
{"name" : "CheckNodeUnschedulable"}
CheckVolumeBinding
predicate 根据卷(它请求的卷)评估 pod 是否可以适合绑定和未绑定 PVC。
- 对于绑定的 PVC, predicate 会检查给定节点是否满足对应 PV 的节点关联性。
- 对于未绑定 PVC,该 predicate 会搜索可满足 PVC 要求且给定节点满足 PV 节点关联性的可用 PV。
如果所有绑定 PVC 都有与节点兼容的 PV,且所有未绑定 PVC 都可与可用并兼容节点的 PV 匹配,该 predicate 会返回 true。
{"name" : "CheckVolumeBinding"}
{"name" : "CheckVolumeBinding"}
NoDiskConflict
predicate 检查 pod 请求的卷是否可用。
{"name" : "NoDiskConflict"}
{"name" : "NoDiskConflict"}
MaxGCEPDVolumeCount
predicate 检查 Google Compute Engine(GCE)持久磁盘(PD)的最大数量。
{"name" : "MaxGCEPDVolumeCount"}
{"name" : "MaxGCEPDVolumeCount"}
MaxCSIVolumeCountPred
predicate 决定应将多少 Container Storage Interface(CSI)卷附加到节点,以及该数量是否超过配置的限制。
{"name" : "MaxCSIVolumeCountPred"}
{"name" : "MaxCSIVolumeCountPred"}
MatchInterPodAffinity
predicate 检查 pod 关联性/反关联性规则是否允许该 pod。
{"name" : "MatchInterPodAffinity"}
{"name" : "MatchInterPodAffinity"}
3.2.3.1.1.2. 其他静态 predicates
OpenShift Container Platform 还支持下列 predicates:
如果启用了 Taint Nodes By Condition 功能,则无法使用 CheckNode-*
predicates。Taint Nodes By Condition 功能默认启用。
CheckNodeCondition
predicate 检查 pod 是否可以调度到报告 磁盘 不足、网络不可用 或 未就绪 状况的节点。
{"name" : "CheckNodeCondition"}
{"name" : "CheckNodeCondition"}
CheckNodeLabelPresence
predicate 检查节点上是否存在所有指定的标签,而不考虑其值。
{"name" : "CheckNodeLabelPresence"}
{"name" : "CheckNodeLabelPresence"}
checkServiceAffinity
predicate 检查 ServiceAffinity 标签是否对于节点上调度的 pod 来说是相同的。
{"name" : "checkServiceAffinity"}
{"name" : "checkServiceAffinity"}
PodToleratesNodeNoExecuteTaints
predicate 检查 pod 容限是否容忍节点 NoExecute
污点。
{"name" : "PodToleratesNodeNoExecuteTaints"}
{"name" : "PodToleratesNodeNoExecuteTaints"}
3.2.3.1.2. 常规 predicates
下列常规 predicates 检查是否通过非关键 predicates 和必要 predicates 的检查。非关键 predicates 是指只有非关键 pod 必须通过检查的 predicates,而必要 predicates 是指所有 pod 都必须通过检查的 predicates。
默认调度程序策略包含常规 predicates。
非关键常规 predicates
PodFitsResources
predicate 根据资源可用性(CPU、内存和 GPU 等)决定适合性。节点可以声明其资源容量,然后 pod 可以指定它们所需要的资源。适合性基于请求的资源,而非使用的资源。
{"name" : "PodFitsResources"}
{"name" : "PodFitsResources"}
必要常规 predicates
PodFitsHostPorts
predicate 决定节点是否有空闲端口用于请求的 pod 端口(不存在端口冲突)。
{"name" : "PodFitsHostPorts"}
{"name" : "PodFitsHostPorts"}
HostName
predicate 根据 Host 参数以及与主机名称匹配的字符串来确定适合性。
{"name" : "HostName"}
{"name" : "HostName"}
MatchNodeSelector
predicate 根据 pod 中定义的节点选择器(nodeSelector)查询来确定适合性。
{"name" : "MatchNodeSelector"}
{"name" : "MatchNodeSelector"}