Thanks! We'll be in touch in the next 12 hours
Oops! Something went wrong while submitting the form.

Unveiling the Magic of Kubernetes: Exploring Pod Priority, Priority Classes, and Pod Preemption

Jai Kishore

Cloud & DevOps

Introduction:

Generally, during the deployment of a manifest, we observe that some pods get successfully scheduled, while few critical pods encounter scheduling issues. Therefore, we must schedule the critical pods first over other pods. While exploring, we discovered a built-in solution for scheduling using Pod Priority and Priority Class. So, in this blog, we’ll be talking about Priority Class and Pod Priority and how we can implement them in our use case.

Pod Priority:

It is used to prioritize one pod over another based on its importance. Pod Priority is particularly useful when critical pods cannot be scheduled due to limited resources.

Priority Classes:

This Kubernetes object defines the priority of pods. Priority can be set by an integer value. Higher-priority values have higher priority to the pod.

Understanding Priority Values:

Priority Classes in Kubernetes are associated with priority values that range from 0 to 1000000000, with a higher value indicating greater importance.

These values act as a guide for the scheduler when allocating resources. 

Pod Preemption:

It is already enabled when we create a priority class. The purpose of Pod Preemption is to evict lower-priority pods in order to make room for higher-priority pods to be scheduled.

Example Scenario: The Enchanted Shop

Let's dive into a scenario featuring "The Enchanted Shop," a Kubernetes cluster hosting an online store. The shop has three pods, each with a distinct role and priority:

Priority Class:

  • Create High priority class: 

CODE: https://gist.github.com/velotiotech/98ca82a608330048f520532e58131d8f.js

  • Create Medium priority class:

CODE: https://gist.github.com/velotiotech/39c327a9fbe9cd1b07cfed2d1895a056.js

  • Create Low priority class:

CODE: https://gist.github.com/velotiotech/76d0d28f4eb82d1d3161a862e462a090.js

Pods:

  • Checkout Pod (High Priority): This pod is responsible for processing customer orders and must receive top priority.

Create the Checkout Pod with a high-priority class:

CODE: https://gist.github.com/velotiotech/7b7ae26b6b5d6471c972e27c0008979f.js

  • Product Recommendations Pod (Medium Priority):

This pod provides personalized product recommendations to customers and holds moderate importance.

Create the Product Recommendations Pod with a medium priority class:

CODE: https://gist.github.com/velotiotech/d26ba42293812615bff76a2c9b72dfdf.js

  • Shopping Cart Pod (Low Priority):

This pod manages customers' shopping carts and has a lower priority compared to the others.

Create the Shopping Cart Pod with a low-priority class:

CODE: https://gist.github.com/velotiotech/d7daa50063a99adc67736a4cda5cb3c5.js

With these pods and their respective priority classes, Kubernetes will allocate resources based on their importance, ensuring smooth operation even during peak loads.

Commands to Witness the Magic:

  • Verify Priority Classes:

kubectl get priorityclasses

Note: Kubernetes includes two predefined Priority Classes: system-cluster-critical and system-node-critical. These classes are specifically designed to prioritize the scheduling of critical components, ensuring they are always scheduled first.

  • Check Pod Priority:

Conclusion:

In Kubernetes, you have the flexibility to define how your pods are scheduled. This ensures that your critical pods receive priority over lower-priority pods during the scheduling process. To get deeper into the concepts of Pod Priority, Priority Class, and Pod Preemption, you can find more information by referring to the following links.

Get the latest engineering blogs delivered straight to your inbox.
No spam. Only expert insights.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings

Unveiling the Magic of Kubernetes: Exploring Pod Priority, Priority Classes, and Pod Preemption

Introduction:

Generally, during the deployment of a manifest, we observe that some pods get successfully scheduled, while few critical pods encounter scheduling issues. Therefore, we must schedule the critical pods first over other pods. While exploring, we discovered a built-in solution for scheduling using Pod Priority and Priority Class. So, in this blog, we’ll be talking about Priority Class and Pod Priority and how we can implement them in our use case.

Pod Priority:

It is used to prioritize one pod over another based on its importance. Pod Priority is particularly useful when critical pods cannot be scheduled due to limited resources.

Priority Classes:

This Kubernetes object defines the priority of pods. Priority can be set by an integer value. Higher-priority values have higher priority to the pod.

Understanding Priority Values:

Priority Classes in Kubernetes are associated with priority values that range from 0 to 1000000000, with a higher value indicating greater importance.

These values act as a guide for the scheduler when allocating resources. 

Pod Preemption:

It is already enabled when we create a priority class. The purpose of Pod Preemption is to evict lower-priority pods in order to make room for higher-priority pods to be scheduled.

Example Scenario: The Enchanted Shop

Let's dive into a scenario featuring "The Enchanted Shop," a Kubernetes cluster hosting an online store. The shop has three pods, each with a distinct role and priority:

Priority Class:

  • Create High priority class: 

CODE: https://gist.github.com/velotiotech/98ca82a608330048f520532e58131d8f.js

  • Create Medium priority class:

CODE: https://gist.github.com/velotiotech/39c327a9fbe9cd1b07cfed2d1895a056.js

  • Create Low priority class:

CODE: https://gist.github.com/velotiotech/76d0d28f4eb82d1d3161a862e462a090.js

Pods:

  • Checkout Pod (High Priority): This pod is responsible for processing customer orders and must receive top priority.

Create the Checkout Pod with a high-priority class:

CODE: https://gist.github.com/velotiotech/7b7ae26b6b5d6471c972e27c0008979f.js

  • Product Recommendations Pod (Medium Priority):

This pod provides personalized product recommendations to customers and holds moderate importance.

Create the Product Recommendations Pod with a medium priority class:

CODE: https://gist.github.com/velotiotech/d26ba42293812615bff76a2c9b72dfdf.js

  • Shopping Cart Pod (Low Priority):

This pod manages customers' shopping carts and has a lower priority compared to the others.

Create the Shopping Cart Pod with a low-priority class:

CODE: https://gist.github.com/velotiotech/d7daa50063a99adc67736a4cda5cb3c5.js

With these pods and their respective priority classes, Kubernetes will allocate resources based on their importance, ensuring smooth operation even during peak loads.

Commands to Witness the Magic:

  • Verify Priority Classes:

kubectl get priorityclasses

Note: Kubernetes includes two predefined Priority Classes: system-cluster-critical and system-node-critical. These classes are specifically designed to prioritize the scheduling of critical components, ensuring they are always scheduled first.

  • Check Pod Priority:

Conclusion:

In Kubernetes, you have the flexibility to define how your pods are scheduled. This ensures that your critical pods receive priority over lower-priority pods during the scheduling process. To get deeper into the concepts of Pod Priority, Priority Class, and Pod Preemption, you can find more information by referring to the following links.

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings