Kubernetes Curriculum
On this page
- Kubernetes Scheduler
- Scheduling Factors
- 1. Resource Requests
- 2. Node Selector
- 3. Affinity Rules (Advanced)
- 4. Taints and Tolerations
- Default Scheduling Algorithm
- Default Scheduling Example
- Scheduling Process in Detail
- Step 1: Pod Creation
- Step 2: Scheduler Detects It
- Step 3: Filtering
- Step 4: Scoring
- Step 5: Binding
- Step 6: kubelet Starts Pod
- Viewing Scheduler Decisions
- Scheduler Configuration
- Common Scheduling Mistakes
- Mistake 1: No Resource Requests
- Mistake 2: Overcommitted Node
- Mistake 3: No Taints on Special Nodes
- Summary
Kubernetes Scheduler
Imagine you have 10 servers and 100 pods that need to run. Which pod runs on which server?
That decision is made by the Kubernetes Scheduler — a component that watches for new pods and assigns them to nodes.
Without proper scheduling, you could have:
- All pods on one server (overloaded)
- Empty servers while others are full (wasteful)
- Incompatible workloads on the same server
- Pods failing because they need specific resources
The scheduler solves this with intelligent placement rules.
How the Scheduler Works
Key point: The scheduler makes placement decisions, kubelet executes them.
Scheduling Factors
1. Resource Requests
Scheduler won't place pod on node unless it has free resources.
2. Node Selector
Scheduler filters to only nodes matching the selector.
3. Affinity Rules (Advanced)
More flexible than nodeSelector.
4. Taints and Tolerations
Used for specialized nodes (GPUs, high-memory, etc.).
Default Scheduling Algorithm
Kubernetes uses a two-phase algorithm:
Phase 1: Filter (yes/no)
- Does node have enough CPU? YES/NO
- Does node have enough memory? YES/NO
- Does node match nodeSelector? YES/NO
- Can node tolerate pod taints? YES/NO
Result: List of eligible nodes
Phase 2: Score (best?)
- Balance pod distribution across nodes
- Consider pod affinity/antiaffinity
- Consider image locality
- Prioritize spreading
Result: Best-scoring node wins
Default Scheduling Example
Scheduling Process in Detail
Step 1: Pod Creation
Pod is created with status.phase: Pending and no spec.nodeName.
Step 2: Scheduler Detects It
Scheduler has a watch on all pods. It sees:
- Pod is pending
- Pod has no nodeName assignment
- Pod should be scheduled
Step 3: Filtering
Scheduler applies all filters:
Step 4: Scoring
Scheduler scores candidates:
Step 5: Binding
Scheduler creates a Binding object:
Step 6: kubelet Starts Pod
kubelet on node1 sees the binding and starts the pod.
Viewing Scheduler Decisions
Scheduler Configuration
Default scheduler is built-in. But you can:
- Use multiple schedulers (custom logic)
- Adjust scheduler settings (via ConfigMap)
- Enable scheduler plugins (custom filtering/scoring)
Most teams don't need this. But advanced cases might.
Common Scheduling Mistakes
Mistake 1: No Resource Requests
Mistake 2: Overcommitted Node
Fix: Use resource quotas or limit scheduling requests.
Mistake 3: No Taints on Special Nodes
Fix: Use taints to reserve nodes for special workloads.
Summary
The Kubernetes Scheduler:
What it does:
- Watches for new pods
- Finds eligible nodes (filtering)
- Scores and picks best node (scoring)
- Assigns pod to node
What matters:
- Resource requests (CPU/memory)
- Labels/selectors
- Affinity rules
- Taints and tolerations
Next: File 02 explains nodeSelector — simple pod-to-node assignment.