Kubernetes scheduler Predicates and Priorities¶
In Kubernetes, the default scheduling process operates through two main phases to determine the most suitable Node for a pending Pod: Predicates (Filtering) and Priorities (Scoring)^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
Predicates (Filter)¶
The Predicates phase functions as a filtering step. When scheduling a Pod, the scheduler concurrently launches multiple threads (specifically, 16 Goroutines in default configurations) to evaluate all Nodes in the cluster^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]. The goal is to identify which Nodes are capable of running the Pod based on a set of mandatory rules^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
The default filtering policies are categorized into several types^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]:
- GeneralPredicates: These rules verify fundamental resource availability, such as ensuring the Node has sufficient CPU and memory to accommodate the Pod's
requests^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]. - Volume Related Rules: These filters manage constraints related to persistent storage Volumes^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
- Host Related Rules: These checks ensure the Pod satisfies conditions specific to the Node itself. A common example is
PodToleratesNodeTaints, which checks if the Pod can tolerate the "taints" applied to a Node^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]. - Pod Related Rules: These rules evaluate the relationship between the pending Pod and the Pods already running on the Node. A key example is
PodAffinityPredicate, which checks for affinity or anti-affinity requirements^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
The outcome of this phase is a list of candidate Nodes that passed all filters^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
Priorities (Scoring)¶
Once the candidate list is established, the Priorities phase ranks these Nodes to select the optimal host^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]. Each candidate Node receives a score between 0 and 10 based on various priority strategies^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
Common scoring strategies include:
- LeastRequestedPriority: This algorithm calculates the score based on the amount of idle resources. It effectively selects the Node with the most available CPU and memory^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
- BalancedResourceAllocation: This strategy aims to prevent resource fragmentation (e.g., a Node with exhausted CPU but plenty of free memory). It calculates the variance between the fractions of requested resources (CPU, memory, volume) and favors the Node where resource allocation is most balanced^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
- Other Priorities: Additional scoring methods include
NodeAffinityPriority,TaintTolerationPriority, andInterPodAffinityPriority^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
The Node with the highest final score is selected to run the Pod^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
Configuration¶
The Kubernetes scheduler allows for customization of these behaviors. Users can enable or disable specific policies by providing a configuration file or a ConfigMap to the kube-scheduler^[400-devops-06-kubernetes-k8s-paas-kubernetes.md]. Furthermore, weights can be assigned to different Priorities to influence the final scheduling decision, allowing for fine-tuned control over how the scheduler evaluates the cluster^[400-devops-06-kubernetes-k8s-paas-kubernetes.md].
Related Concepts¶
- [[Kubernetes Resources and QoS]]
- Kubernetes Priority and Preemption
Sources¶
400-devops-06-kubernetes-k8s-paas-kubernetes.md