Kubernetes Resource Management: Requests, Limits, and Quality of Service (QoS)

Manno.dev
3 min readMay 21, 2024

--

Introduction

Kubernetes is a powerful and flexible platform for container orchestration, but to fully leverage its potential, it is crucial to understand resource management. In this article, we will explore the concepts of requests and limits, and how they impact the Quality of Service (QoS) of pods with Guaranteed, Burstable, and Best-Effort levels. Additionally, we will discuss the pros and cons of each QoS class.

Understanding Kubernetes Resources: Requests and Limits

Requests

Requests define the minimum amount of resources (CPU and memory) that a container needs to operate. Kubernetes uses these values to schedule pods on nodes. If a node doesn’t have enough resources to meet a pod’s requests, the pod won’t be scheduled on that node.

Example of request configuration:

resources:
requests:
cpu: "500m" # 500 milliCPU, or 50% of a CPU core
memory: "256Mi" # 256 Megabytes of memory

Limits

Limits specify the maximum amount of resources a container can use. If a container tries to use more resources than its limits, Kubernetes will intervene, such as throttling the CPU usage or terminating the container if it exceeds the memory limit.

Example of limit configuration:

resources:
limits:
cpu: "1" # 1 CPU core
memory: "512Mi" # 512 Megabytes of memory

Combining Requests and Limits

It is good practice to specify both requests and limits to ensure efficient resource utilization and prevent node overload.

Here’s a complete example:

resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"

Quality of Service (QoS) in Kubernetes

Kubernetes assigns a Quality of Service (QoS) class to each pod based on its resource requests and limits. The QoS class helps Kubernetes decide which pods to keep running during resource pressure situations.

1. Guaranteed

A pod is classified as Guaranteed if every container in the pod has both requests and limits set, and they are equal.

Example:

resources:
requests:
cpu: "1"
memory: "1Gi"
limits:
cpu: "1"
memory: "1Gi"

Pros:

  • Highest Priority: Guaranteed pods are the least likely to be terminated during resource pressure.
  • Stable Performance: Resources are guaranteed, leading to predictable and stable performance.

Cons:

  • Resource Inefficiency: Resources must be reserved even if not fully utilized, potentially leading to inefficient cluster usage.

2. Burstable

A pod is classified as Burstable if each container has requests lower than its limits or if only some containers have requests and limits defined.

Example:

resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"

Pros:

  • Flexibility: Burstable pods can use additional resources (up to the limits) when available, allowing greater elasticity.
  • Better Resource Utilization: Compared to Guaranteed pods, Burstable pods can adapt better to varying workloads.

Cons:

  • Medium Priority: Burstable pods may be terminated if the cluster is under resource pressure, making them less reliable than Guaranteed pods.
  • Variable Performance: Applications may experience variable performance based on resource availability.

3. Best-Effort

A pod is classified as Best-Effort if no container in the pod has requests or limits set.

Example:

resources: {}

Pros:

  • Maximum Flexibility: Best-Effort pods can utilize any available resources without request or limit restrictions.
  • Cost-Effective: Since they don’t reserve specific resources, Best-Effort pods are suitable for less critical or temporary workloads.

Cons:

  • Lowest Priority: Best-Effort pods are the first to be terminated during resource pressure, making them unsuitable for critical applications.
  • Unpredictable Performance: The lack of guaranteed resources means performance can be highly variable and unreliable.

Conclusion

Properly managing resources in Kubernetes is essential to ensure cluster stability and efficiency. By accurately defining requests and limits, you can better control resource utilization, prevent node overload, and improve the Quality of Service (QoS) of your pods.

Implementing these best practices will help you fully leverage Kubernetes’ capabilities, maintaining a robust and scalable infrastructure.

Continuously monitor application performance and adjust resource configurations based on the actual needs of your production environment to optimize resource management effectively.

Summary of QoS Classes: Pros and Cons

Guaranteed

  • Pros: Highest priority, stable performance
  • Cons: Resource inefficiency

Burstable

  • Pros: Flexibility, better resource utilization
  • Cons: Medium priority, variable performance

Best-Effort

  • Pros: Maximum flexibility, cost-effective
  • Cons: Lowest priority, unpredictable performance

--

--