3.2.2. 创建调度程序策略文件

您可以通过使用所需的 predicates 和 priorities 创建 JSON 文件来更改默认调度行为。然后,您可以通过 JSON 文件生成配置映射,并将 cluster 调度程序对象指定为使用该配置映射。

流程

配置调度程序策略:

  1. 使用所需的 predicates 和 priorities,创建一个名为 policy.cfg 的 JSON 文件。

    调度程序 JSON 文件示例

    {
    "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}
            ]
    }

    1
    根据需要添加 predicates。
    2
    根据需要添加 priorities。
  2. 根据调度程序 JSON 文件创建配置映射:

    $ oc create configmap -n openshift-config --from-file=policy.cfg <configmap-name> 1
    1
    输入配置映射的名称。

    例如:

    $ oc create configmap -n openshift-config --from-file=policy.cfg scheduler-policy

    输出示例

    configmap/scheduler-policy created

  3. 编辑调度程序 Operator 自定义资源以添加配置映射:

    $ oc patch Scheduler cluster --type='merge' -p '{"spec":{"policy":{"name":"<configmap-name>"}}}' --type=merge 1
    1
    指定配置映射的名称。

    例如:

    $ oc patch Scheduler cluster --type='merge' -p '{"spec":{"policy":{"name":"scheduler-policy"}}}' --type=merge

    在修改了 Scheduler 配置资源后,等待 openshift-kube-apiserver pod 重新部署。这可能需要几分钟。只有重新部署 pod 后,新的调度程序才会生效。

  4. 通过查看 openshift-kube-scheduler 命名空间中调度程序 pod 的日志,来验证已配置调度程序策略。以下命令检查由调度程序注册的 predicates 和 priorities:

    $ oc logs <scheduler-pod> | grep predicates

    例如:

    $ oc logs openshift-kube-scheduler-ip-10-0-141-29.ec2.internal | grep predicates

    输出示例

    Creating scheduler with fit predicates 'map[MaxGCEPDVolumeCount:{} MaxAzureDiskVolumeCount:{} CheckNodeUnschedulable:{} NoDiskConflict:{} NoVolumeZoneConflict:{} GeneralPredicates:{} MaxCSIVolumeCountPred:{} CheckVolumeBinding:{} MaxEBSVolumeCount:{} MatchInterPodAffinity:{} PodToleratesNodeTaints:{}]' and priority functions 'map[InterPodAffinityPriority:{} LeastRequestedPriority:{} ServiceSpreadingPriority:{} ImageLocalityPriority:{} SelectorSpreadPriority:{} EqualPriority:{} BalancedResourceAllocation:{} NodePreferAvoidPodsPriority:{} NodeAffinityPriority:{} TaintTolerationPriority:{}]'