Sub topic 8
Preemption: making room for a higher-priority Pod
This chapter assumes you know how Pods, Nodes, and kubectl work. It also assumes you have seen a PriorityClass and know that the scheduler places Pods in a queue ordered by priority. Here you will see what happens when a high-priority Pod fits on no node.
When preemption happens
The scheduler first tries to place a Pod normally. It filters out nodes that lack enough free requested CPU or memory, then scores the nodes that remain. If no node passes the filters, the Pod would normally stay Pending.
Preemption is the fallback. The scheduler looks for a node where removing one or more lower-priority Pods would let the pending Pod fit. If it finds such a node, it deletes those Pods, called victims, and places the pending Pod there.
Preemption only considers Pods with a strictly lower priority than the pending Pod. Pods of equal or higher priority are never victims.
How the scheduler chooses victims
For each candidate node, the scheduler works out the smallest set of lower-priority Pods whose removal makes room. It then picks one node using these rules, in order:
- Fewest PodDisruptionBudget violations.
- Lowest highest-priority victim.
- Lowest sum of victim priorities.
- Fewest victims.
- The victim that started most recently.
A worked example
Suppose a node has 2 CPUs allocatable and runs a Pod with a 1.5 CPU request and the default priority of 0. You then create this Pod, which needs 1 CPU:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
globalDefault: false
description: "For latency-sensitive workloads that may preempt lower-priority Pods."
---
apiVersion: v1
kind: Pod
metadata:
name: important-app
spec:
priorityClassName: high-priority
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "1"
memory: 512MiOnly 0.5 CPU is free, so important-app does not fit. The priority-0 Pod is a valid victim, so the scheduler deletes it.
Check what happened:
kubectl describe pod important-app | grep -iE 'priority|qos|nominated'
kubectl get events --field-selector reason=PreemptedThe first command shows the Pod's priority and its Nominated Node. The second lists Preempted events on the victims.
Nominated node
Victims get a graceful termination period, so the node is not free right away. The scheduler records the chosen node in the pending Pod's status.nominatedNodeName. This reserves the space in the scheduler's view, so lower-priority Pods are not placed into it in the meantime.
The nomination is only a hint. If another node becomes free first, or a still higher-priority Pod arrives, the Pod can be bound somewhere else.
Exercise
A node is full. A pending Pod has priority 500. The node runs one Pod with priority 500 and one with priority 100. Which Pods can the scheduler choose as victims?
Show answer
Only the priority-100 Pod. Victims must have strictly lower priority than the pending Pod, so the priority-500 Pod is protected. If deleting the priority-100 Pod does not free enough room, the pending Pod stays Pending.