【问题标题】:understanding percentageOfNodesToScore default behavior了解 percentOfNodesToScore 默认行为
【发布时间】:2022-10-24 00:36:20
【问题描述】:
Kubernetes 调度程序在尝试调度 pod 时可能会使用集群节点的子集,具体取决于集群中的节点数量和调度程序Configuration。
我想知道默认行为是什么,因为kube-scheduler-config API 文档不清楚:
percentOfNodesToScore[必需] int32
PercentageOfNodesToScore 是一旦发现可运行 pod 的所有节点的百分比,调度程序将停止在集群中搜索更多可行节点。这有助于提高调度程序的性能。不管这个标志的值是什么,调度程序总是试图找到至少“minFeasibleNodesToFind”的可行节点。示例:如果集群大小为 500 个节点,并且该标志的值为 30,则调度程序一旦找到 150 个可行节点就停止寻找更多可行节点。当值为0时,默认的节点百分比(基于集群大小的5%--50%)将被计分。
【问题讨论】:
标签:
kubernetes
scheduling
【解决方案1】:
kubernetes 1.25 中的调度程序默认行为在 KubeSchedulerConfiguration percentageOfNodesToScore 设置为 0 时启用。
默认行为是扫描 50% 的节点,该百分比通过集群中的节点数除以 125 来减少(例如:2500 个节点/125=20 => 50% - 20 点 => 扫描 30%节点)。要扫描的最小节点是总或 100 个节点的 5%。
要全面了解调度程序的行为,请深入了解 Kubernetes 源代码。函数numFeasibleNodesToFind(链接到kubernetes 1.25)
const (
// SchedulerError is the reason recorded for events when an error occurs during scheduling a pod.
SchedulerError = "SchedulerError"
// Percentage of plugin metrics to be sampled.
pluginMetricsSamplePercent = 10
// minFeasibleNodesToFind is the minimum number of nodes that would be scored
// in each scheduling cycle. This is a semi-arbitrary value to ensure that a
// certain minimum of nodes are checked for feasibility. This in turn helps
// ensure a minimum level of spreading.
minFeasibleNodesToFind = 100
// minFeasibleNodesPercentageToFind is the minimum percentage of nodes that
// would be scored in each scheduling cycle. This is a semi-arbitrary value
// to ensure that a certain minimum of nodes are checked for feasibility.
// This in turn helps ensure a minimum level of spreading.
minFeasibleNodesPercentageToFind = 5
)
// == trucated == //
// numFeasibleNodesToFind returns the number of feasible nodes that once found, the scheduler stops
// its search for more feasible nodes.
func (sched *Scheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes int32) {
if numAllNodes < minFeasibleNodesToFind || sched.percentageOfNodesToScore >= 100 {
return numAllNodes
}
adaptivePercentage := sched.percentageOfNodesToScore
if adaptivePercentage <= 0 {
basePercentageOfNodesToScore := int32(50)
adaptivePercentage = basePercentageOfNodesToScore - numAllNodes/125
if adaptivePercentage < minFeasibleNodesPercentageToFind {
adaptivePercentage = minFeasibleNodesPercentageToFind
}
}
numNodes = numAllNodes * adaptivePercentage / 100
if numNodes < minFeasibleNodesToFind {
return minFeasibleNodesToFind
}
return numNodes
}