Kubernetes – Use Pod Priority and Preemption

Tram Ho

Preamble

As we all know, Kubernetes is an open source system known for being able to smoothly deploy containerized applications and especially scalable workloads. It scales your workloads based on their resource usage. As workload is increased, multiple application replicas can be created.

When an application is critical to your product and you want to ensure that new versions of the application are always scheduled in advance, even when your Kubernetes cluster is under financial pressure. original. One often thought-out solution to this problem is to always over-over-supply your cluster so there is always some resource waiting available for scaling scenarios. This solution usually works, but the cost is higher because you’ll have to pay for resources that are mostly idle most of the time. However, another solution is to use “Pod Priority and Preemption” .

So what are Pod Priority and Preemption and how are they used, we will find out in this article.

What is Priority Pod and Preemption?

Pod priority and preemption or pod priority and pod priority is a scheduled feature for the stable provided pod since Kubernetes version 1.14 allows you to reach the level of your scheduling priority. is desirable for pods to host their critical applications without the need to provide too many resources waiting for clusters. It is also a way to improve resource utilization in your clusters without losing the stability of essential workloads deployed in the cluster.

  • Pod priority : Shows how important one pod is compared to other pods, and ranks pods in order based on priority.
  • Pod preemption : Allow your Kubernetes cluster to remove (evict) or attempt to preempt lower priority pods so that higher priority pods can be set calendar if there is no free space on an appropriate node.

PriorityClass

To be able to use Pod priority and preemption, first of all, we need to mention the concept of PriorityClass :

  • A PriorityClass is a non-namespaced object and it is part of the scheduler used to specify the mapping from the name of a priority class to a priority pod value. Values ​​are an integer value and the larger it is, the higher the priority. This value is specified in the field that requires PriorityClass to be value .
  • PriorityClass can have any 32-bit integer value less than or equal to 1 billion. Larger numbers are reserved for critical system pods that are usually not removed or pre-occupied.
  • The name of a PriorityClass must have a value of a DNS subdomain and must not begin with system-
  • The globalDefault option globalDefault to indicate that this PriorityClass value will be used for pods that do not have a priorityClassName field. Only a single PriorityClass globalDefault set to true can exist in the system. If no PriorityClass has globalDefault , the priority of the pod without a priorityClassName field is 0.
  • The optional description is an optional string. It is used to add a detailed description of PriorityClass so that the cluster’s users know when they should use this PriorityClass.
  • In addition, PriorityClass has a field named PreemptionPolicy to define its behavior corresponding to priority. By default, its values ​​are PreemptionPolicy=PreemptLowerPriority , which will allow those PriorityClass pods to prioritize those with lower priority. If PreemptionPolicy=Never the pods in that PriorityClass will not give priority to other pods.

How to use pod priority and preemption

Create one or more PriorityClass

For example, we can create some sample PriorityClass as follows:

Create pod priorities

Once we have created one or more PriorityClass, we will be able to create priority pods by adding a priorityClassName field with a value of the name of a PriorityClass. For example:

Conclusion

Using Pod Priority and Preemption is a great method you can use to improve the use of your cluster resources, you can also help prevent lower priority workloads from affecting your workload. The amount of work is important in your cluster, especially in the event that the cluster begins to reach its resource capacity limits.

Reference source

Share the news now

Source : Viblo