Are Kubernetes requests really guaranteed?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Kubernetes is a powerful orchestration platform, widely adopted for managing containerized applications at scale. It offers rich features for resource management, including CPU and memory requests and limits. However, a common question that arises is: Are Kubernetes requests really guaranteed?
Understanding Kubernetes Resource Requests and Limits
Before delving into whether requests are truly guaranteed, it is essential to comprehend the role of requests and limits in Kubernetes:
- Requests: This is the amount of CPU or memory that you explicitly "ask" Kubernetes to allocate to your container. It influences scheduling decisions since Kubernetes will only schedule a pod on a node if the node has the capacity to handle the resource request.
- Limits: While requests specify the minimum resources a container needs, limits define the maximum resources it can consume. If a pod tries to exceed its defined limits, Kubernetes will take measures such as throttling (for CPU) or killing the container (for memory).
Are Requests Truly Guaranteed?
The concept of "guarantee" can be subjective, depending on what aspect you consider—scheduling or runtime behavior. Let's explore each:
Scheduling Guarantees
Upon scheduling a pod, Kubernetes uses requests to decide which nodes can host the pod. Nodes with insufficient allocatable resources will not be considered. This provides a scheduling guarantee, as Kubernetes ensures that the needed capacity is available on the selected node at the scheduling time.
Runtime Guarantees
Once a pod is running, the "guarantee" becomes less concrete. Kubernetes does its best to ensure requests are met, but this can be affected by several factors:
- Resource Contention: Even though requests are respected during scheduling, running workloads can lead to resource contention. For example, if multiple containers on a node compete for available CPU cycles, they might not get their requested CPU shares. Kubernetes uses a fair sharing algorithm that can alter how resources are distributed during runtime.
- Node Pressure: If a node experiences pressure (e.g., due to other workloads not constrained by limits), the ability to deliver requested resources might be compromised.
- Priority and Preemption: Kubernetes allows setting priorities. When the cluster is under resource pressure, low-priority pods might face eviction to ensure higher priority pods receive their requested resources.
Examples of Runtime Behavior
Consider a scenario where two pods, Pod A and Pod B, are scheduled on the same node:
- Pod A: Requests 500m CPU, no limit.
- Pod B: Requests 500m CPU, no limit.
If Pod A starts consuming up to 800m CPU, Pod B might get less than its requested 500m, because CPU is a compressible resource, managed on a fair-share basis unless limited. Memory requests are not compressible, so memory requests could likely be more closely adhered to, unless the node is under severe pressure.
Subtopics to Consider
Quality of Service (QoS) Classes
Kubernetes introduces Quality of Service (QoS) classes to manage pods' runtime behavior further:
- Guaranteed: Pods that have equal requests and limits for all container resources. They are least likely to be killed by the kubelet when the node experiences resource pressure.
- Burstable: Pods with requests less than limits. Such pods are somewhat protected but can be throttled or evicted under pressure.
- Best-Effort: Pods with neither requests nor limits. These are the first to be evicted under resource pressure.
Real-Time Workloads
For real-time or latency-critical applications, relying solely on Kubernetes requests might not be sufficient. In such cases, employing real-time kernels or dedicating nodes to critical workloads should be considered to ensure resource availability.
Cluster Autoscaling
Enabling cluster autoscaling can help maintain adequate resource availability by provisioning more nodes as demand increases, thereby alleviating pressure on existing nodes and honoring resource requests more effectively.
Summary Table
Below is a summary of key considerations regarding Kubernetes resource requests:
| Aspect | Description |
| Scheduling | Requests ensure pods are scheduled on nodes with adequate resources. |
| Runtime Guarantee | Less concrete; resource contention and node pressure can affect guarantees. |
| CPU vs Memory | CPU requests can be throttled (compressible), while memory is typically not. |
| QoS Classes | Different levels: Guaranteed, Burstable, and Best-Effort. |
| Priority / Preemption | High-priority pods may lead to low-priority pod evictions under pressure. |
| Autoscaling | Helps accommodate fluctuating resource demands by adding nodes. |
In conclusion, while Kubernetes resource requests come with a level of "guarantee" during the scheduling phase, runtime assurances are influenced by various dynamic factors. Understanding these nuances and leveraging techniques such as QoS classes, proper autoscaling, and prioritization can help maintain desired resource availability.

