Skip to main content
Kubernetes internalsLesson 12 of 12

Priority and Preemption

When nodes are full, a new Pod usually waits in Pending (Which Node Gets the Pod (Scheduling)). But what if it is an important Pod that must not wait? Let's follow priority and preemption, which decide who to keep alive first when resources run short.

paymentPending
batch-aRunning
node-1 free room0
node-1 · fullpaymenthigh priorityPriorityPriorityClassSchedulerpicks Pod nodePDBbatch min 1batch-alow · 100batch-blow · 100webequal · 100000corednssystem toppaymentrunningvalue 100000Schedule me
RequestResponse / reportWatchAppears in a later step

What you will learn

  • Priority is a number; higher goes first
  • Only lower-priority Pods can be preempted
  • Preemption honors PDBs only on a best-effort basis
  • How an evicted Pod shuts down and goes Pending
  • Why system components get the highest priority

Drain vs preemption​

Drain (emptying a node)Preemption
Who starts itAn operatorThe scheduler
WhyNode maintenance or upgradeMaking room for a higher-priority Pod
If it would violate a PDBRefuses and waitsProceeds anyway if there is no other way
Evicted PodsRecreated on other nodesRecreated by the controller, but Pending if no room

The details of drain and PDBs are in Draining Nodes and Upgrading the Cluster.

Try it yourself​

kubectl get priorityclasses # Grades and values, including system-*
kubectl get pods -A -o custom-columns=NAME:.metadata.name,CLASS:.spec.priorityClassName,PRIORITY:.spec.priority # Grade each Pod uses
kubectl get events -A --field-selector reason=Preempted # Pods evicted by preemption
kubectl get pod <pod> -o jsonpath='{.status.nominatedNodeName}' # Node the waiting Pod is headed for
kubectl get pdb -A # Disruption budgets (best-effort only)

Check yourself

  1. A priority-100000 Pod cannot fit on a full node. Which Pods are candidates for preemption?
  2. Your batch app has a PDB. Does that protect it from preemption?
  3. Batch Pods keep disappearing, and kubectl get events shows frequent Preempted events. What should you suspect first?

Further reading: Pod priority and preemption · Disruptions