NashTech Insights

How to use the PriorityClass and Preemption in Kubernetes

Mohd Muzakkir Saifi
Mohd Muzakkir Saifi
Table of Contents

Hello learners, We will learn something new in today’s blog about priorityclass and preemption in the Kubernetes. Basically, this blog is related to the Kubernetes. In Kubernetes. So We will learn about the Pod Priority. Pod priority is an important feature in the Kubernetes cluster and it helps with the pod scheduling. Basically, It allows Kubernetes to compare different pods based on their priority numbers and make decisions about which pods should be scheduled first or not. Now, let’s explore the two important concepts related to pod priority.

  1. Preemption
  2. Priority Class

1. Preemption

This is one of the concepts in Kubernetes. The pod preemption feature in Kubernetes enables Kubernetes to remove lower-priority pods from nodes[ if it has high-priority pods] when there are higher-priority pods waiting to be scheduled, but there are no available resources on the nodes then it will not remove

2. Priority Class

In Kubernetes, We can assign a specific priority to a pod. Only you need to define the priority class as per the requirement.
A priority class is set using the PriorityClass object in the YAML file, which is not associated with a specific namespace, and it has a value that determines the priority. The value can be set as 1,000,000,000 (one billion) or lower[ It can be any value as per your requirements]. The higher number means the higher priority assigned to the particular pod.

In the above code you can see, I have defined the pod-with-priority. The priority class name (priorityClassName) is used in the pod specification to define the priority for a pod.

I have used the same pod-with-priority in the above yaml to give the reference.


Now let’s look into the example of the priorityClass:

kind: PriorityClass
  name: pods-with-priority

value: 100
globalDefault: false
description: "pods priority"

apiVersion: v1
kind: Pod
  name: nginx
    env: test-env
  - name: web-blog
    image: nginx:latest
    imagePullPolicy: IfNotPresent
  priorityClassName: pods-with-priority

High PriorityClass:

Now We have two types of default high-priority classes in Kubernetes:-

  • System-node-critical: This particular class has a value of 2000001000. It is used by static pods such as etcd, kube-apiserver, kube-scheduler, and Controller Manager. These static pods utilize this priority class.
  • System-cluster-critical: This specific class has a value of 2000000000. It is utilized by addon pods such as coredns, calico controller, metrics server, and others. These addon pods make use of this priority class.

Workflow of Pod Priority & Pod Preemption in Kubernetes

  1. When a pod is deployed with a PriorityClassName, the priority admission controller retrieves the priority value based on the PriorityClassName assigned to it. If there are multiple pods in the scheduling queue, the scheduler organizes their scheduling order according to their priority. This means that high-priority pods are scheduled before low-priority pods.
  2. However, if there are no available nodes with sufficient resources to accommodate a high-priority pod, the preemption logic comes into play. The scheduler will preempt (evict) a low-priority pod from a node in order to schedule the higher-priority pod. The evicted pod is given a graceful termination time of 30 seconds as the default. Note that if pods have terminationGracePeriodSeconds set for preStop container Lifecycle Hooks, it will override the default 30 seconds.
  3. Nevertheless, if the scheduling requirements cannot be met for any reason, the scheduler proceeds with scheduling the lower-priority pods.”


Basically, we have gone through the pod priority like how we can set the pod priority with the help of PriorityClass in the YAML configuration. If you like this blog please subscribe to our blogs and I always come up with new and interesting blogs..
You can also read my old blogs here and on other technologies.

Mohd Muzakkir Saifi

Mohd Muzakkir Saifi

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

%d bloggers like this: