Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 359 of 8025. Advanced Kubernetes ConfigurationFree lesson

Managing Preemption and Pod Eviction Policies

Understand how the scheduler preempts lower-priority pods to free up node resources for high-priority workloads when the cluster reaches capacity.

In this lesson, you will learn how Kubernetes intelligently clears space for critical tasks by removing lower-priority workloads when your cluster runs out of resources.

The Problem: Cluster Congestion

Imagine your cluster is a busy office building. When a high-priority executive (a high-priority Pod) arrives and all the desks are taken, the building manager must ask less essential staff (low-priority Pods) to clear their desks so the executive can get to work. This process is called preemption.

How Preemption Works

Preemption is the scheduler's way of resolving resource contention. When a Pod with a high priorityClassName cannot find a node with enough capacity, the scheduler looks for nodes where it can "evict" Pods that have a lower priority than the incoming one.

Once the scheduler identifies a victim (the lower-priority Pod), it deletes that Pod. The victim is terminated, the resources are freed, and the high-priority Pod is scheduled onto the node.

A Practical Example

If you have a critical data-processing task, you define a PriorityClass with a high value. If your cluster is full of background "cleanup" jobs, the scheduler will trigger preemption:

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority-tasks
value: 1000000
globalDefault: false
description: "Used for critical data processing."

When you apply this class to your Pod spec, the scheduler gains the authority to "evict" any Pods lacking this priority if the node is hitting its capacity limits (e.g., CPU or Memory).

Important Constraints

It is important to remember that preemption is not indiscriminate. The scheduler will not preempt Pods if doing so doesn't actually allow the high-priority Pod to fit. Furthermore, the scheduler honors PodDisruptionBudgets (if configured) to ensure that preempting one Pod doesn't violate your minimum availability requirements for that service.

Preemption is a powerful tool to ensure that your "must-run" applications always have the resources they need, even in a crowded cluster, by sacrificing your "nice-to-have" background tasks.

Key Takeaway: Preemption automatically resolves resource shortages by terminating lower-priority Pods to make room for high-priority workloads, ensuring your most critical services remain performant and available.