In Kubernetes, scheduling means making sure that the Pods are matched to Nodes that can provide the required resources for said Pods. It is one of the core features of Kubernetes. It can also be known as the process of placing Pods in a Kubernetes cluster according to their resource requirements.
Pod priority, Preemption and Pod priority class change Pod scheduling behaviour.
- Kubernetes Cluster
Pod Scheduling Concepts
Pod priority is a scheduling feature that enables Kubernetes to schedule Pods on nodes by comparing the priority number of different Pods and scheduling them accordingly.
Two main concepts in Pod priority are:
- Pod Preemption
- Pod Priority Class
Pod Preemption allows a Kubernetes cluster to evict/preempt lower-priority Pods from the nodes when high-priority Pods are waiting to be scheduled and when there is a lack of resources in the node.
Pod Priority Class
A Pod priority class is required to assign a Pod to a certain priority in the cluster. Priority for a Pod can be set using the PriorityClass object. The value of the PriorityClass object determines the priority of the Pod.
Kubernetes Pod Priority Value
priorityClassName will be used in a Pod to set its priority. If we set
Never, the Pods will not be evicted by the priority class.
PriorityClassis to use the
Kubernetes Pod Priority Value & Class Example
The example below has a PriorityClass object and a Pod that uses the particular priority class.
High Priority Classes
There are two high-priority classes available by default on a Kubernetes cluster. They can instruct the scheduler to give Pods with those classes the highest priority available during Pod scheduling.
This class has a default value of
2000000000. Add-on Pods like coredns, flannel, metrics server, etc., use this priority class.
This class has a default value of
2000001000. Pods like etcd, kube-apiserver, and controller manager use this priority class.
Unnecessarily applying these classes to less important pods is not recommended.
How Does Kubernetes Pod Priority & Preemption Work?
- When a Pod is deployed with
PriorityClassName, the admission controller gets the priority value using the value of
- If Pods are in the scheduling queue, the scheduler will arrange for them to be scheduled on nodes based on their priority. High-priority Pods are placed ahead of low-priority Pods.
- When no nodes are available with the required resources to run a high-priority Pod, the preemption process starts, and low-priority Pods are evicted to make space for high-priority Pods.
- Evicted Pods get a graceful termination time of 30-seconds by default.
- If the resource requirements of the high-priority Pod are not met even after eviction, then the low-priority Pods are reinstated in the cluster.
Pod Priority FAQs
1. What is a Kubernetes DaemonSet Priority?
Daemonsets have similar priorities compared to Pods. To keep Daemonsets stable and avoid eviction during a resource crunch, we need to set a higher Pod priority class for the Daemonset.
2. What Is the Relation Between Pod QoS, Pod Priority & Preemption?
kubelet will first consider the Quality of Service (QOS) class and then the Pod priority value to evict Pods during resource shortage in the nodes, and the preemption logic starts up when high-priority Pods are waiting to be scheduled.
3. What Is the Significance of Pod Priority?
When we deploy apps in Kubernetes, we may not want to kill certain applications during resource crunches like logging agents, databases, payment provider services, etc.
To ensure that these Pods and Daemonsets are always available, we need to create a hierarchy of Pod tiers with priorities. During a resource crunch in the clusters, the
kubelet will try to kill the low-priority Pods to accommodate the higher-priority mission-critical Pods.
The Kubernetes scheduler checks for Pods with no nodes assigned and finds the best node for a particular Pod to run on. The scheduler will assign a node to the Pod based on the different concepts that apply to it, like
Pod Priority Class,
In this article, we learned about the different scheduling concepts in Kubernetes. We also learned to set Pod priority and Pod classes and the significance of setting up Pod Priority in a Cluster.
Thank you for reading. Stay tuned for another article on Kubernetes runtime security and logging. Please comment below if you have any questions.