We can assign priorities to pods, and as a result apod with a lower priority might be stopped to allow a higher priority pod to be scheduled if the resources of a system are low.
The pod's priority could also be a quick fix to stop low-priority pods in order to run the high-priority ones until we are able add more resources to the system.
To assign a priority to a pod, we first create a kubernetes object called a PriorityClass.
The priority could be between "1" - lowest priority - and "1000000000" - highest priority -.
Here is a simple diagram of high-priority preemptingpods, where a low-priority pod is stopped to allow a high-priority pod to run on the node:
Below is a simple diagram of high-priority non-preemptingpods in:
For a random pod without a priority class assigned to it, it gets associated with the default priority class, or if the default priority class doesn't exist, the pod gets "0" as priority as we see below in our example pod:
We can check the priority classes defined in our system using the below command:
Below is an example of a priority class named "priority_1":
The globalDefault parameter tells kubernetes to use this PriorityClass for pods that are defined without a "priorityClassName".
The preemptionPolicy is set to "never", which means that the pods associated with that class are non-preemptingpods.
Non-preempting high-priority pods will sit in front of the low-priority pods in the queue, but the already running pods with low-priority will not be "sacrificed" to "give room" for the non-preempting high-priority pods to be able to run on a node.
Non-preempting high-priority pods will wait in the queue until resources are available for them to be able to run on the node.
The preepreemptionPolicy, if not set in the PriorityClass object, gets the default value "PreemptLowerPriority".
The "PreemptLowerPriority" tells pods to run before lower-priority pods, lower priority pods could be stopped to "make room" for the higher- priority ones.
We can check our priority class using the below command:
Below is an example of a pod that uses the above priority class:
Affinity and anti-affinity rules override high-priority rules.
If we want to define a default priority class for pods that don't have one assigned to them, we could do it as follows:
To check our priority class after running the "kubectl apply" on its Yaml file, we use the below command: