Back to articles

PriorityClass and preemption: deciding who gets evicted first

Without PriorityClasses, every pod in your cluster has the same priority and a full cluster removes pods in an order nobody chose. This article covers what priority affects (scheduling order, preemption, kubelet eviction), what it doesn't (the kernel's OOM killer, drains), a four-class scheme to start from, and how to stop every team from picking the top class.

A cluster that never runs out of room doesn't need priorities. Every other cluster already has an eviction order, whether anyone chose it or not. With no PriorityClasses defined, every pod has priority zero, and when capacity runs short the outcome depends on arrival order and on which pod happens to be using more than it requested. Your ingress controller and a nightly report job are treated as equals.

Setting priorities is how you choose that order on purpose. It is also a way to cause an outage with four lines of YAML: one class with a high value, handed to the wrong workload, removes other people's pods to make room for it.

Who this is for: platform engineers running shared clusters that sometimes fill up, and anyone who has seen a pod disappear with the event reason Preempted.

What you walk away with: a precise list of what priority affects and what it doesn't, a small class scheme to start from, and two ways to stop every team from picking the highest class.

What priority affects

A PriorityClass is a cluster-scoped object that maps a name to an integer. A pod references it with priorityClassName, and the priority admission controller copies the integer into spec.priority when the pod is created. If the class doesn't exist, the pod is rejected. The copy happens once: a class's value can't be changed afterwards, and if you delete a class, the docs say existing pods "remain unchanged".

That integer is then used in three places.

Where What priority does
Scheduling queue Pending pods are ordered by priority. Higher goes first.
Preemption If a pending pod fits nowhere, the scheduler may remove lower-priority pods from a node to make room.
Kubelet node-pressure eviction When a node runs short of memory or disk, priority is one of three ranking factors.

Queue order

A higher-priority pod is tried first, but if it can't be scheduled the scheduler carries on with the others. It doesn't block the queue.

Preemption

When a pending pod P fits on no node, the scheduler looks for a node where removing one or more pods with lower priority than P would make P fit. If it finds one, those pods are deleted and P's status.nominatedNodeName is set to that node.

Know these properties before you rely on it:

How nodes are filtered and scored before any of this happens is covered in how the scheduler picks a node.

Node-pressure eviction

When the kubelet has to evict pods because a node is under memory or disk pressure, it ranks them by:

  1. whether the pod's usage of the starved resource exceeds its requests,
  2. pod priority,
  3. usage relative to requests.

The result, in the words of the documentation: pods whose usage exceeds requests "are evicted based on their Priority and then by how much their usage level exceeds the request", and pods using less than they requested "are evicted last, based on their Priority".

So a high priority protects a pod from the kubelet only if its requests are honest. A high-priority pod running above its memory request is ranked for eviction ahead of a low-priority pod that stays inside its request. Priority and accurate requests are one control, not two.

What priority doesn't affect

The kernel's OOM kill order. If memory runs out faster than the kubelet can evict, the Linux OOM killer decides, and it works from oom_score_adj, which the kubelet sets from the pod's QoS class: -997 for Guaranteed, 1000 for BestEffort, and a value in between for Burstable based on the memory request. Priority isn't in that calculation. A BestEffort pod with your highest custom class still gets the highest adjustment there is.

There is one exception: the kubelet also sets -997 for containers in pods with system-node-critical priority. The upcoming memory pressure article follows that path in detail.

Limits and throttling. Priority gives a container no extra CPU time and no extra memory.

Running pods while there is room. Priority only matters when something is short.

Drains and other API-initiated evictions. Neither the eviction API page nor the drain task in the Kubernetes docs mentions priority. What they describe for that path is PodDisruptionBudgets, which API-initiated evictions respect.

Scheduler preemption doesn't look at QoS. The docs call priority and QoS "two orthogonal features with few interactions": the scheduler's preemption logic "does not consider QoS", and the OOM adjustment doesn't consider priority.

The built-in classes

Every cluster ships with two classes:

Class Value Meant for
system-node-critical 2000001000 Components a node can't work without
system-cluster-critical 2000000000 Components the cluster can't work without

Your own classes can use any value up to 1,000,000,000 (and down to -2,147,483,648). Higher values are reserved, and you can't create a class whose name starts with system-.

These two exist so that DNS, the CNI agent and similar components can always be rescheduled. The docs add a caveat: marking a pod as critical "is not meant to prevent evictions entirely; it only prevents the pod from becoming permanently unavailable".

Don't put application workloads in them. A workload in a system class can preempt everything you define yourself, and the kubelet's eviction manager refuses to evict pods at these priorities under node pressure.

Kubernetes itself doesn't reserve them for kube-system. In the release-1.37 source, the priority admission plugin only checks that the class exists, and the ResourceQuota plugin has no default restriction. Some platforms add one with the quota mechanism described below: the GCE kube-up script and GKE 1.36 do.

Static pods are a special case. They don't support priorityClassName; the manifest sets priority directly.

Two fields with side effects

preemptionPolicy: Never

A class with preemptionPolicy: Never gets the queue position that goes with its value but can't remove other pods. It waits until room appears. The default is PreemptLowerPriority.

This suits work that should go ahead of the queue without destroying running work, such as an urgent batch job. Such pods can still be preempted by higher-priority pods, and they are subject to scheduler back-off like any other pod, so lower-priority pods may be scheduled ahead of them while they wait.

globalDefault: true

One class may be marked as the default for pods without a priorityClassName. Without one, those pods get priority zero. The hazards:

The lower-risk arrangement is to have no global default, or one with value 0 that only gives the default a name. Raise the workloads that matter; don't lower everything else.

Preemption and PodDisruptionBudgets

PDBs don't stop preemption. The documentation's heading for this is "PodDisruptionBudget is supported, but not guaranteed": the scheduler looks for victims whose PDBs wouldn't be violated, "but if no such victims are found, preemption will still happen, and lower priority Pods will be removed despite their PDBs being violated."

A PDB does influence which node is chosen. If the lowest-priority pods on one node are protected by a PDB, the scheduler may pick another node with higher-priority victims (still lower than the preemptor). A PDB on a low-priority workload can move the damage to a more important one.

A PDB is therefore the control for API-initiated evictions such as drains, and only a preference under preemption. If a workload must not be preempted, the answer is its priority, not its budget. The PodDisruptionBudget article covers what PDBs do guarantee.

A small scheme to start from

This scheme is our suggestion, not something from the Kubernetes docs, and the values are arbitrary apart from the reasoning below. With many more than four classes, it gets hard to say which one a workload belongs in.

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: platform-critical
value: 1000000
description: "Platform components other workloads depend on: ingress, policy engines, GitOps controllers. Platform team only."
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: production-high
value: 100000
description: "User-facing production services where losing a replica is felt immediately."
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: standard
value: 0
globalDefault: true
description: "Default. Everything without a reason to be elsewhere."
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: batch-low
value: -5
preemptionPolicy: Never
description: "Interruptible work: reports, CI jobs, reprocessing. First to go when capacity is short."

The reasoning behind the choices:

Preemption deletes pods, so anything in standard or batch-low has to tolerate being stopped at any moment: more than one replica where availability matters, and proper shutdown handling.

Keeping the high classes for those who need them

A PriorityClass is cluster-scoped, and by default any pod in any namespace may reference any class. The Kubernetes docs carry a warning about this: a user could create pods at the highest priorities, "causing other Pods to be evicted/not get scheduled". A scheme where everyone picks the top class orders nothing.

Option 1: quota scoped by PriorityClass

A ResourceQuota can be scoped to a class, so that it counts only pods using it:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: production-high
  namespace: team-a
spec:
  hard:
    pods: "20"
    requests.cpu: "16"
    requests.memory: 32Gi
  scopeSelector:
    matchExpressions:
    - scopeName: PriorityClass
      operator: In
      values: ["production-high"]

On its own this only limits namespaces where the quota exists; a namespace without it can use the class freely. To make a class usable only where a matching quota exists, the API server needs an admission configuration file passed with --admission-control-config-file:

apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: "ResourceQuota"
  configuration:
    apiVersion: apiserver.config.k8s.io/v1
    kind: ResourceQuotaConfiguration
    limitedResources:
    - resource: pods
      matchScopes:
      - scopeName: PriorityClass
        operator: In
        values: ["platform-critical"]

With this in place, a pod using platform-critical is rejected in any namespace that has no quota covering that class. The trade-off: it needs an API server flag, so it is only available where you run the control plane yourself or your provider exposes that setting. The ResourceQuota article covers how quota rejections show up.

Option 2: an admission policy

A ValidatingAdmissionPolicy needs no API server access. The one below was tested on GKE 1.36 (class renamed).

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: restrict-platform-priority
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["pods"]
  validations:
  - expression: "!has(object.spec.priorityClassName) || object.spec.priorityClassName != 'platform-critical'"
    message: "platform-critical is reserved for platform namespaces."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: restrict-platform-priority
spec:
  policyName: restrict-platform-priority
  validationActions: [Warn, Audit]
  matchResources:
    namespaceSelector:
      matchExpressions:
      - key: priority.example.com/platform
        operator: DoesNotExist

Start with [Warn, Audit] to see what it would reject, then switch to [Deny]. Three caveats:

RBAC covers the other half. Creating or changing PriorityClass objects should be limited to cluster administrators, which matters when you audit your bindings.

Seeing it in a cluster

# Classes and their values
kubectl get priorityclass

# What each pod actually got
kubectl get pods -A -o custom-columns='NS:.metadata.namespace,NAME:.metadata.name,CLASS:.spec.priorityClassName,PRIORITY:.spec.priority,PREEMPT:.spec.preemptionPolicy'

# Pods that were preempted
kubectl get events -A --field-selector reason=Preempted

# A pending pod that has triggered preemption
kubectl get pod <pod> -o jsonpath='{.status.nominatedNodeName}{"\n"}'

The scheduler records an event with reason Preempted on each victim. Events expire, so ship them somewhere if you need them later; the events guide explains how.

Kubernetes v1.37 adds an alpha feature gate, off by default, InPlacePodVerticalScalingSchedulerPreemption: with it, a deferred in-place resize of a higher-priority pod can preempt lower-priority pods on its node.

Checklist

  1. Decide on three or four classes, each with a description that tells people when to use it.
  2. Keep the default at zero, with or without a named globalDefault class.
  3. Give platform components and node agents a class above application workloads.
  4. Put interruptible work in a low, non-preempting class, and check how your autoscaler treats its value.
  5. Restrict the top class by quota or admission policy before announcing it.
  6. Check that requests are realistic for anything you expect priority to protect.
  7. Keep application workloads out of the system-* classes, and check whether your cluster enforces that.
  8. Don't count on PDBs to stop preemption.