Kubernetes default scheduling policies¶
Kubernetes default scheduling policies define the logic the kube-scheduler uses to assign new Pods to specific Nodes. This process is divided into two main phases: Predicates (Filtering) and Priorities (Scoring)^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
Scheduling Workflow¶
1. Predicates (Filtering)¶
In this phase, the scheduler determines which nodes are capable of running the Pod. To improve performance, Kubernetes starts 16 Goroutines to concurrently evaluate all Nodes in the cluster^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
The filtering logic relies on several default policy groups^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]:
- GeneralPredicates: Checks basic resource availability (CPU and memory) on the Node^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
- Volume-related Rules: Ensures the Node can support the Pod's persistent volume requirements^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
- Host-specific Rules: Verifies conditions specific to the Node, such as
PodToleratesNodeTaints(checking if the Pod can tolerate the Node's taints)^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]. - Pod-related Rules: Includes checks like
PodAffinityPredicate, which evaluates the affinity or anti-affinity relationships between the pending Pod and existing Pods on the Node^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
2. Priorities (Scoring)¶
After filtering, the remaining nodes are scored on a scale of 0 to 10. The node with the highest score is selected^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
Common default priority strategies include^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]:
- LeastRequestedPriority: Selects the node with the most idle resources (CPU and Memory). The algorithm calculates the available capacity relative to the total capacity to favor nodes that are less utilized^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
- BalancedResourceAllocation: Penalizes nodes where resource allocation is imbalanced (e.g., CPU is fully allocated while Memory is free). It aims to distribute different types of resources evenly across the cluster^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
- Other Priorities: Includes
NodeAffinityPriority,TaintTolerationPriority, andInterPodAffinityPriority^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
Configuration¶
While the policies above are defaults, Kubernetes allows for customization. Administrators can enable or disable specific rules and assign weights to priorities to control scheduling behavior via configuration files or ConfigMaps^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
Related Concepts¶
- Pod
- [[PriorityClass]]
- [[Taints and Tolerations]]
- Kubernetes Resource Model
Sources¶
^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]