KubernetesCX · Priority and PreemptionPriority and preemption
Preemption mechanics — how the scheduler evicts lower-priority Pods
What you'll learn
- Trace the preemption mechanics (n+1 search, nomination, graceful termination)
- Identify the failure modes (no preemption candidates, PDB blocking, graceful termination timeout)
- Apply the discipline of testing preemption
- Build the operational discipline of monitoring preemption events
Prerequisites
Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16
Preemption is the scheduler’s mechanism for evicting lower-priority Pods to make room for higher-priority Pods. This lesson walks the mechanics, the failure modes, and the discipline.
When preemption happens
flowchart LR
A[Higher-priority Pod pending] --> B{Cluster has room?}
B -->|Yes| C[Schedule normally]
B -->|No| D{Lower-priority Pods on a node?}
D -->|Yes| E["Preempt: evict lower-priority Pods"]
D -->|No| F[Pod stays Pending]
Preemption happens when:
- A higher-priority Pod is pending.
- The scheduler cannot find a node where the Pod fits.
- There are lower-priority Pods on some node.
- The scheduler evicts the lower-priority Pods to make room.
The n+1 search
flowchart TD
A[Higher-priority Pod cannot fit] --> B[Search for a node]
B --> C{Node has lower-priority Pods?}
C -->|No| D[Try next node]
C -->|Yes| E[Can higher-priority Pod fit after eviction?]
E -->|No| D
E -->|Yes| F[Nominate candidates for removal]
F --> G[Schedule higher-priority Pod]
G --> H[Gracefully terminate lower-priority Pods]
The n+1 search:
- The scheduler iterates over nodes.
- For each node, it checks if the higher-priority Pod could fit after removing some lower-priority Pods.
- If yes, it nominates the lower-priority Pods for removal.
- The scheduler schedules the higher-priority Pod.
- The kubelet gracefully terminates the lower- priority Pods.
PodList ordering
flowchart TD
A[Candidates for removal] --> B{Sort by...}
B --> C[Highest priority first to remove]
B --> D[Lowest priority first to remove]
B --> E[Most requested first to remove]
B --> F[Least requested first to remove]
The scheduler’s nomination strategy:
- Prefer removing fewer Pods. Remove the largest Pods that free the most resources.
- Prefer removing lower-priority Pods. Lower priority first.
- Respect PDBs. Don’t remove Pods that would violate a PDB.
The scheduler optimises for minimal disruption: the fewest Pods removed to fit the new Pod.
Graceful termination
flowchart LR
A[Scheduler evicts Pod] --> B{Send SIGTERM}
B --> C[Container performs graceful shutdown]
C --> D{terminationGracePeriodSeconds elapsed?}
D -->|No| E[Wait]
E --> D
D -->|Yes| F[Send SIGKILL]
F --> G[Pod removed]
Graceful termination:
- The kubelet sends SIGTERM to the Pod’s containers.
- The containers perform graceful shutdown (close connections, flush state).
- After
terminationGracePeriodSeconds(default 30s), the kubelet sends SIGKILL. - The Pod is removed.
A long-running graceful shutdown (e.g., database
flush) may need a longer terminationGracePeriodSeconds.
The failure modes
flowchart LR
A[Failure modes] --> B[No preemption candidates]
A --> C[PDB blocking]
A --> D[Graceful termination timeout]
A --> E[Cascading preemptions]
The failure modes:
- No preemption candidates. All lower-priority Pods are protected by PDBs; the higher-priority Pod stays Pending.
- PDB blocking. A PDB is too restrictive; the scheduler cannot evict without violating it.
- Graceful termination timeout. A container does
not shut down within
terminationGracePeriodSeconds; SIGKILL is sent. Data loss possible. - Cascading preemptions. Preempting one Pod triggers another preemption; the cluster thrashes.
Quiz
Knowledge check · 4 questions
Q1. What does the scheduler do immediately after selecting preemption victims?
Q2. Preemption moves the evicted Pods to another node.
Q3. A critical Pod stays Pending for minutes after the scheduler has already chosen its victims; explain the delay and shorten it.
`fraud-scoring` at priority 1000000 has been Pending for 4m30s. `kubectl describe pod` shows `nominatedNodeName: worker-03` and no further FailedScheduling events. On `worker-03`, two `etl-loader` Pods have been Terminating for four minutes; their spec sets `terminationGracePeriodSeconds: 600` and a `preStop` hook that drains a queue.
Q4. How long can elapse between the scheduler choosing preemption victims and the preempting Pod actually starting, and what sets that duration?
Passing score: 75%. Answers are checked in this browser.
The operational discipline
Preemption in production rests on five non-negotiable elements:
- Configure PDBs with headroom. Allow preemption to evict Pods.
- Set sensible terminationGracePeriodSeconds. Long enough for graceful shutdown.
- Monitor preemption events. Alert on frequent preemption; the cluster is under pressure.
- Test preemption. Quarterly: simulate a cluster under pressure; verify higher-priority Pods are scheduled.
- Document the preemption policy. The runbook lists the priority classes and their preemption behaviour.
Preemption is a powerful tool, but it requires discipline. PDBs that are too restrictive prevent preemption; PDBs that are too loose allow eviction of critical Pods. The balance is operational.