blog
  • Blogs
    • Medium Articles
      • Linux
        • 40 Powerful Linux Networking Commands You Must Know.
        • These (Linux) VI Editor Shortcuts You Must Know
        • Bash/Linux Interview Questions for DevOps Engineers
        • Page 1
      • Git
        • 40 Powerful Git Commands Every Developer Should Know
        • 10 Git Best Practices That Every Developer Must Know
      • DevOps/SRE Interview Questions and Answers
        • Top DevOps/SRE Interview Questions and Answers on AWS VPC
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Terraform Best Practices
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Kubernetes Best Practices
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Dockerfiles
        • Top 10 Common DevOps/SRE Interview Questions and Answers on Grafana
      • Installation
        • Docker Installation on Ubuntu 20/22
        • Install WireGuard VPN on Docker Compose
        • Install Redis on Docker Compose
        • Gravitee Docker Compose
      • Kubernetes Series 2025
        • Understanding Kubernetes: Part 1 -Control Plane
        • Understanding Kubernetes: Part 2 -Worker Node
        • Understanding Kubernetes: Part 3 -Pod
        • Understanding Kubernetes: Part 4-ReplicaSets
        • Understanding Kubernetes: Part 5 -Deployment
        • Understanding Kubernetes: Part 6 -DaemonSets
        • Understanding Kubernetes: Part 7 -StatefulSet
        • Understanding Kubernetes: Part 8 -ConfigMap
        • Understanding Kubernetes: Part 9 -Kubernetes Secret
        • Understanding Kubernetes: Part 10 -StorageClass
        • Understanding Kubernetes: Part 11 -Persistent Volume (PV)
        • Understanding Kubernetes: Part 12 -Persistent Volume Claim (PVC)
        • Understanding Kubernetes: Part 13 -Services
        • Understanding Kubernetes: Part 14 -ClusterIP Service
        • Understanding Kubernetes: Part 15 -NodePort Service
        • Understanding Kubernetes: Part 16 -Load Balancer Service
        • Understanding Kubernetes: Part 17 -Ingress
        • Understanding Kubernetes: Part 18 -Ingress Controller
        • Understanding Kubernetes: Part 19 -Headless Service
        • Understanding Kubernetes: Part 20-Network Policy
        • Understanding Kubernetes: Part 21 -CNI
        • Understanding Kubernetes: Part 22 Kubernetes Resource Requests & Limits
        • Understanding Kubernetes: Part 23 Node Selector
        • Understanding Kubernetes: Part 24 Taints and Tolerations
        • Understanding Kubernetes: Part 25 Affinity and Anti-Affinity
        • Understanding Kubernetes: Part 26 Preemption and Priority
        • Understanding Kubernetes: Part 27 Role and RoleBinding
        • Understanding Kubernetes: Part 28 ClusterRole and ClusterRoleBinding
        • Understanding Kubernetes: Part 29 Service Account
        • Understanding Kubernetes: Part 30 Horizontal Pod Autoscaler (HPA)
        • Understanding Kubernetes: Part 31 Vertical Pod Autoscaler (VPA)
        • Understanding Kubernetes: Part 33 Startup Probe
        • Understanding Kubernetes: Part 34 Liveness Probe
        • Understanding Kubernetes: Part 35 Readiness Probe
        • Understanding Kubernetes: Part 36 Container Network Interface (CNI)
        • Understanding Kubernetes: Part 37 Container Runtime Interface (CRI)
        • Understanding Kubernetes: Part 38 Container Storage Interface (CSI)
      • Cloudflare
        • Cloudflare Tunnel for Secure HTTP Routing
      • Nginx
        • Nginx use cases that every engineer must know
Powered by GitBook
On this page
  1. Blogs
  2. Medium Articles
  3. Kubernetes Series 2025

Understanding Kubernetes: Part 26 Preemption and Priority

PreviousUnderstanding Kubernetes: Part 25 Affinity and Anti-AffinityNextUnderstanding Kubernetes: Part 27 Role and RoleBinding

Last updated 3 months ago


What is a Pod Priority?

A Pod Priority defines the importance of a Pod relative to others. Higher-priority Pods get scheduled before lower-priority ones. If resources are insufficient, Kubernetes may preempt (evict) lower-priority Pods to make room for higher-priority ones.

Defining a Pod Priority Class

Pod priorities are defined using PriorityClasses, which assign numerical values to indicate importance.

Example: Creating a Priority Class

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority
value: 1000
preemptionPolicy: PreemptLowerPriority
globalDefault: false
  • value: Determines the priority level; higher values indicate higher priority.

  • preemptionPolicy: Defines whether the Pod can preempt lower-priority Pods (PreemptLowerPriority).

  • globalDefault: If true, this priority applies to all Pods by default.

Assigning a Priority to a Pod

After defining a PriorityClass, assign it to a Pod:

apiVersion: v1
kind: Pod
metadata:
  name: critical-app
spec:
  priorityClassName: high-priority
  containers:
    - name: app
      image: my-app

This Pod is now considered high-priority and may preempt lower-priority Pods if needed.


What is Preemption?

Preemption occurs when a high-priority Pod cannot be scheduled due to resource constraints. Kubernetes then evicts lower-priority Pods to free up resources for the high-priority Pod.

Preemption Process

  1. A high-priority Pod cannot be scheduled due to lack of resources.

  2. Kubernetes identifies lower-priority Pods that can be evicted.

  3. The lower-priority Pods are terminated.

  4. The high-priority Pod is scheduled.

Controlling Preemption

By setting preemptionPolicy: Never, you can prevent a Pod from evicting other workloads:

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: non-preempting-priority
value: 500
preemptionPolicy: Never

This ensures that Pods with this priority will not preempt lower-priority Pods.


Use Cases

1. Ensuring Critical Workloads Run First

  • Assign higher priority to critical applications to guarantee their availability.

2. Protecting Low-Priority Batch Jobs

  • Set low priority for batch processing jobs to avoid interference with real-time applications.

3. Controlled Eviction of Non-Essential Workloads

  • Preempt lower-priority workloads during resource shortages, ensuring vital services remain operational.


Removing a Priority Class

If a PriorityClass is no longer needed, remove it using:

kubectl delete priorityclass high-priority

This prevents future Pods from using this priority but does not affect running Pods.


Conclusion

Kubernetes Preemption and Priority allow fine-grained control over workload scheduling, ensuring that essential applications always have the resources they need. By assigning priorities wisely, you can optimize cluster stability and resource allocation efficiently.


In My Previous Role

As a Senior DevOps Engineer, I leveraged Kubernetes Priority and Preemption to ensure efficient workload scheduling:

  • Critical Services: Assigned high-priority classes to essential applications to prevent downtime.

  • Batch Jobs: Set lower priorities for non-essential batch jobs to minimize their impact on critical workloads.

  • Resource Optimization: Used preemption to dynamically allocate resources based on workload demand, ensuring efficient cluster utilization.

🚀 Ready to Master Kubernetes?

Take your Kubernetes journey to the next level with the Master Kubernetes: Zero to Hero course! 🌟 Whether you’re a beginner or aiming to sharpen your skills, this hands-on course covers:

✅ Kubernetes Basics — Grasp essential concepts like nodes, pods, and services. ✅ Advanced Scaling — Learn HPA, VPA, and resource optimization. ✅ Monitoring Tools — Master Prometheus, Grafana, and AlertManager. ✅ Real-World Scenarios — Build production-ready Kubernetes setups.

🎓 What You’ll Achieve

💡 Confidently deploy and manage Kubernetes clusters. 🛡️ Secure applications with ConfigMaps and Secrets. 📈 Optimize and monitor resources for peak performance.

Don’t miss your chance to become a Kubernetes expert! 💻✨

🚀 Master Terraform: Infrastructure as Code

🔥 Start Learning Now: Join the Master Terraform Course

🔥 Start Learning Now: [Join the Master Kubernetes Course]()

🚀 Stay ahead in DevOps and SRE! 🔔 and never miss a beat on Kubernetes and more. 🌟

https://cloudops0.gumroad.com/l/k8s
Subscribe now
Preemption and Priority