liveBook · Manning

Preemption

As explained in Kubernetes for Developers

Preemption is the proactive removal of lower-priority Pods to make resources available for higher-priority Pods.

Preemption lets a higher-priority Pod obtain capacity by proactively removing lower-priority Pods instead of remaining Pending until resources become free. Configure it through a PriorityClass and assign that class to the workload. section 5.1.3

Kubernetes applies priority and preemption in several related decisions:

  • The scheduler considers higher-priority Pending Pods first. section 5.1.3
  • Preemption removes lower-priority running Pods when no capacity is available and the higher-priority Pod cannot otherwise be scheduled. section 5.1.3
  • A PriorityClass with preemptionPolicy: Never can rank workloads without allowing them to displace lower-priority Pods. section 5.1.3
  • Managed workloads such as Deployments recreate removed Pods; standalone Pods are not rescheduled automatically. section 5.1.3

Keeping capacity ready for urgent workloads

Run low-priority placeholder Pods in a Deployment to reserve headroom. When a regular Pod with a higher priority arrives, it preempts the placeholders, allowing rapid scheduling. Set placeholder Pods to a lower priority and preemptionPolicy: Never; use multiple replicas sized at least as large as the largest regular Pod. section 6.3.2

Listing 5.5 Chapter05/5.1.3_Priority/priorityclass-preemption.yaml
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority-preemption
value: 1000000
preemptionPolicy: PreemptLowerPriority     #1
globalDefault: false
description: "Critical services."
#1 This priority class will cause eviction of lower priority Pods if there is no available capacity in the cluster.

Inspect a PriorityClass configured to preempt lower-priority Pods when cluster capacity is unavailable. section 5.1.3

Listing 6.10 Chapter06/6.3.2_PlaceholderPod/placeholder-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: placeholder
spec:
  replicas: 10                                  #1
  selector:
    matchLabels:
      pod: placeholder-pod
  template:
    metadata:
      labels:
        pod: placeholder-pod
    spec:
      priorityClassName: placeholder-priority   #2
      terminationGracePeriodSeconds: 0          #3
      containers:
      - name: ubuntu
        image: ubuntu
        command: ["sleep"]                      #4
        args: ["infinity"]                      #4
        resources:
          requests:
            cpu: 200m                           #5
            memory: 250Mi                       #5

Inspect the Deployment pattern for low-priority placeholder Pods that provide spare scheduling capacity. section 6.3.2

How Kubernetes for Developers covers it

How deep it goes
Explains PriorityClass configuration, scheduling effects, rescheduling behavior, and placeholder capacity, but not detailed eviction algorithms.
Examples
Uses high-priority Deployments, non-preempting PriorityClasses, and low-priority placeholder Deployments to demonstrate displacement.
What it assumes
Assumes Pods, Deployments, resource requests, scheduling, and PriorityClasses; emphasizes correct requests and limits before advanced priority configuration.
What you can do after
Configure preemptive and non-preemptive PriorityClasses and operate placeholder Deployments for rapid scheduling headroom.
How it connects
Connects preemption with Kubernetes scheduling, priority classes, eviction, Deployments, and cluster autoscaling.

Also explained in

Compare how 5 books explain preemption →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.