Skip to content

Kubernetes default scheduling strategies

In Kubernetes, the default scheduling process is executed by the kube-scheduler and consists of two main phases: Predicates (Filtering) and Priorities (Scoring).^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

Predicates (Filtering)

The first phase, Predicates, involves filtering the cluster's nodes to determine which ones are suitable for the Pod.^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

The scheduler runs these rules concurrently (typically using 16 Goroutines) to compute a list of feasible nodes.^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

The default strategies are categorized into the following types^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]:

  1. GeneralPredicates: Checks fundamental resource requirements, such as whether the node has sufficient CPU and memory.
  2. Volume-related rules: Checks for persistent volume constraints (e.g., mounting volumes).
  3. Node-related rules: Checks specific conditions of the node itself, such as [[taints-and-tolerations|Node Taints]] (handled by PodToleratesNodeTaints).
  4. Pod-related rules: Checks relationships between the pending Pod and existing Pods on the node, including affinity and anti-affinity rules (e.g., PodAffinityPredicate).

Priorities (Scoring)

After filtering, the Priorities phase scores each feasible node from 0 to 10 to select the best fit.^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

Key default scoring strategies include^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]:

  • LeastRequestedPriority: Calculates the score based on the ratio of available resources to total capacity. This strategy favors nodes with the most idle resources (CPU and Memory).
  • BalancedResourceAllocation: Calculates the variance between the fraction of requested resources (CPU, Memory, Volume). It selects the node with the smallest resource allocation gap to prevent scenarios where one resource type is exhausted while others remain free.

Additional priority strategies include NodeAffinityPriority, TaintTolerationPriority, and InterPodAffinityPriority.^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

Customization

While these strategies are enabled by default, Kubernetes allows for extensive customization.^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]

Administrators can modify the scheduler's behavior by:

  • Specifying a configuration file or creating a ConfigMap.
  • Explicitly enabling or disabling specific rules.
  • Setting weights for specific Priority strategies to influence the final scoring decision.

Sources