How Kubernetes Uses “Quality of Service (QoS) Classes” for pod eviction?

Introduction

In this post, we will know about the Quality of Service (QoS) classes in Kubernetes. We will also understand how these QoS classes influences the decision of pod eviction from a node in a Kubernetes Cluster.

Kubernetes uses Quality Of Service (QoS) Classes and assigns it to each Pod to make decisions of pod eviction.

What is Quality of Service (QoS) class ?

👉 Kubernetes classifies the Pods that you run and allocates each Pod into a specific quality of service (QoS) class.
👉 This classification based on the resource requests of the Containers in that Pod, along with how those requests relate to resource limits. 
👉 QoS classes are used by Kubernetes to decide which Pods to evict from a Node experiencing Node Pressure.

Types of QoS Classes

Quality of Service (QoS) Classes
Quality of Service (QoS) Classes

1️⃣ Guaranteed

👉 They have the strictest resource limits and are least likely to face eviction.
👉 They are guaranteed not to be killed until they exceed their limits or there are no lower-priority Pods that can be preempted from the Node.
👉 Criteria for a Pod to be given a Guaranteed QoS class:
🔹 Every Container in the Pod must have a memory limit and a memory request.
🔹 For every Container in the Pod, the memory limit must equal the memory request.
🔹 Every Container in the Pod must have a CPU limit and a CPU request.
🔹 For every Container in the Pod, the CPU limit must equal the CPU request.

2️⃣ Burstable

👉 Pods that are Burstable have some lower-bound resource guarantees based on the request, but do not require a specific limit.
👉 In the event of Pod eviction due to Node resource pressure, these Pods are evicted only after all BestEffort Pods are evicted.
👉 Criteria for a Pod to be given a Burstable QoS class:
🔹 The Pod does not meet the criteria for QoS class Guaranteed.
🔹 At least one Container in the Pod has a memory or CPU request or limit.

3️⃣ BestEffort

👉 Pods in the BestEffort QoS class can use node resources that aren’t specifically assigned to Pods in other QoS classes. 
👉 For example, if you have a node with 16 CPU cores available to the kubelet, and you assign 4 CPU cores to a Guaranteed Pod, then a Pod in the BestEffort QoS class can try to use any amount of the remaining 12 CPU cores.
👉 The kubelet prefers to evict BestEffort Pods if the node comes under resource pressure.
👉 Criteria for a Pod to be given a BestEffort QoS class:
🔹 A Pod has a QoS class of BestEffort if it doesn’t meet the criteria for either Guaranteed or Burstable.
🔹 In other words, a Pod is BestEffort only if none of the Containers in the Pod have a memory limit or a memory request, and none of the Containers in the Pod have a CPU limit or a CPU request.

Order of eviction

👉 BestEffort => Burstable => Guaranteed
👉 When a Node runs out of resources, Kubernetes will first evict BestEffort Pods running on that Node, followed by Burstable and finally Guaranteed Pods.

References

🔗 Pod Quality of Service Classes (Kubernetes)

"Knowledge Sharing Is Powerful"
Scroll to Top