While deploying the deployment manifest, we found that some of the critical pods are not getting scheduled whereas others are getting scheduled easily. Now, I wanted to make sure that the critical pod gets scheduled first over other pods. I started exploring pod scheduling and then came across one of the native solutions for Pod Scheduling using Pod Priority & Priority Class. So in this blog, we’ll talk about Priority Class & Pod Priority and how we can use them for pod scheduling.
It determines the importance of a pod over another pod. It is most helpful when we need to schedule the critical pods, which are unable to schedule due to resource capacity issues.
It is a non-namespace object. It is used to define the priority. Priority Class objects can have any 32-bit integer value smaller than or equal to 1 billion. The higher the value, the higher will be the priority.
It allows the higher-priority pods to evict the lower-priority pods so that higher-priority pods can be scheduled, which is by default enabled when we create PriorityClass.
Why do we need to set pod priority?
When we are doing the deployment, all the pods have default priority i.e 0. Now all the pods will have an equal value which means all the pods will get equal importance in terms of scheduling. But somehow certain pods go into a pending state due to resource capacity that is critical to schedule over other pods. In that case, we make use of pod priority. The Kubernetes scheduler can even remove the lower-priority pods that are running so that the higher-priority pods can be scheduled.
With the help of priority pods, we can make sure that critical pods are always getting scheduled over lower-priority pods.
Kubernetes Priority Class
Priority Class Example
description: "Priority class for critical workloads"
Now verify whether the priority class was created or not.
Once we have created Priority Class. We need to specify it in our pod so that whenever this pod is going to schedule by schedular then it should be getting important over other pods in a cluster for that we need to add a field named as priorityClassName. which will populates the integer value of the priority class.
Pod Priority Example Manifest
- name: nginx
Once you have created the pod with a priority class then the priority class value & name will attach to it. Verify whether the pod has the given priority class name or not.
Now the above pod will have more priority over other pods that are running as it has a higher integer value than others.
As we talked about at the beginning of this blog as well that preempting allows the higher priority Pods to get scheduled easily over lower-priority pods as preemptPolicy by default is set to PreemptLowerPriority in Priority Class that allows higher priority Pods to preempt lower-priority pods. But It is also possible to make this option disable with preemptionPolicy: Never such that your higher priority can’t preempt lower priority although they will be placed ahead of lower priority pods but these pods now have to wait for schedule until sufficient resources are free.
Kubernetes already ships with two Priority Classes: system-cluster-critical and system-node-critical . These are common classes and are used to ensure that critical components are always scheduled first
With the help of Priority Class. You can easily define how your pod is going to schedule in Kubernetes. It will also make sure that your critical gets priority over lower Priority class pod when it comes to scheduling. For more details about Pod Priority, Priority Class & Pod Preemption you can refer Below Links.
Blog Pundits: Deepak Gupta and Sandeep Rawat
OpsTree is an End-to-End DevOps Solution Provider.
Connect with Us