How does Kubernetes' scheduler work?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Kubernetes is an open-source platform designed to automate deploying, scaling, and managing containerized applications. A key component of Kubernetes that ensures efficient operation and resource utilization is its scheduler. The scheduler is responsible for placing workloads, such as pods, onto nodes based on various constraints and policies. Understanding how Kubernetes' scheduler works is essential for optimizing application deployments and the overall performance of a Kubernetes cluster.
Scheduler Overview
In Kubernetes, the scheduler determines which nodes are most suitable for running a new pod. It takes into account the current state of the cluster and the requirements of the pod. The scheduler follows a series of steps to make decisions:
- Watch New Pods without Nodes: The scheduler continually monitors the cluster for newly created pods that need a node to be assigned.
- Filter Nodes: The scheduler filters out nodes that do not meet the pod's constraints using a set of rules called predicates.
- Score Nodes: The scheduler ranks the filtered nodes based on a set of priority functions to find the most suitable node.
- Bind Pod to Node: Finally, the scheduler assigns the pod to the best node by writing a binding object back to the API server.
Key Components and Functions
Predicates
Predicates are rules that help filter out nodes that cannot accommodate a given pod. Some common predicates include:
- PodFitsResources: Ensures the node has sufficient resources (CPU, memory) for the pod.
- NoDiskConflict: Ensures that a pod can be scheduled onto a node without disk conflicts.
- PodFitsHostPorts: Verifies that no other pod on the node uses the same ports as the requesting pod.
Priorities
Once the available nodes are filtered, they are scored based on priority functions:
- LeastRequestedPriority: Prefers nodes with the least allocated resources, favoring underutilized nodes.
- BalancedResourceAllocation: Strives for balanced resource usage across all resources (CPU and memory).
- NodeAffinityPriority: Schedules pods based on rules specified in the pod's
affinityoranti-affinitysettings.
Binding
After selecting the most suitable node, the scheduler binds the pod to that node by creating a Binding object. This action is recorded in the Kubernetes API server, and the pod is placed onto the node for execution by the kubelet.
Example: Scheduling a Pod
Consider a pod with the following resource requirements:
Here is a simplified flow of how the scheduler would handle this pod:
- The scheduler detects
myapp-podwithout a node assignment. - It filters nodes based on resource requests (
64Mimemory,250mCPU). - Nodes meeting the criteria are scored using priorities.
- The scheduler binds
myapp-podto the node with the highest score, ensuring resource limits are respected.
Scheduler Extensibility
Kubernetes' scheduler is designed to be highly configurable and extensible. Users can create custom schedulers to modify scheduling policies or add new predicates and priorities tailored to specific workloads. Scheduler extensions can be implemented using:
- Scheduler Framework: A pluggable structure that allows for implementing custom scheduling mechanisms.
- Custom Schedulers: Completely separate from the default scheduler, these can be deployed as additional components in the Kubernetes cluster.
Comparison Table
Here's a summary of key concepts within Kubernetes' scheduling:
| Component | Purpose |
| Predicates | Filter out unsuitable nodes based on constraints |
| Priorities | Rank nodes using scoring algorithms |
| Binding | Assign the best node to a pod and record in the cluster |
| Scheduler Framework | Allows the development of custom scheduling logic |
| Custom Schedulers | Provide alternative scheduling policies or features |
Conclusion
Kubernetes' scheduler is integral to ensuring that applications run efficiently within a cluster. Through predicates, priorities, and binding, the scheduler balances resource utilization and fulfills workload requirements. The ability to customize the scheduler allows for flexibility and optimization to meet specific organizational needs. Understanding and leveraging the scheduler can greatly enhance the efficiency and performance of Kubernetes orchestration.
Related reading
- How does one add a node or nodes to an existing YugaByte DB CE cluster?
- How does the GKE metadata server work in Workload Identity
- How health check of Kubernetes work with Istio?
- How I create new namespace in Kubernetes
- How does one detect if one is running within a docker container within Python?
- How does one remove a Docker image?
- How does multi-line logging work in Lambda - CloudWatch
- How does waiting & atomic clock help GCP spanner solve Linearizability and Serializability in distributed transaction?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.