Kubernetes Requests and Limits
Set CPU and memory requests and limits, understand throttling and OOM kills, and learn how QoS classes affect pod behavior.
Requests vs Limits
resources.requests tell Kubernetes how much resource a container is expected to need.
resources.limits tell Kubernetes the maximum it can consume.
Full YAML Example
apiVersion: v1
kind: Pod
metadata:
name: resources-demo
spec:
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
Enforcement Differences
| Resource | What happens at limit |
|---|---|
| CPU | The container may be throttled |
| Memory | The container may be killed with OOMKill |
QoS Classes
| QoS class | General meaning |
|---|---|
| Guaranteed | Requests and limits set equally for all containers |
| Burstable | Some requests or limits set, but not fully guaranteed |
| BestEffort | No requests or limits set |
LimitRange for Namespace Defaults
A LimitRange can set default requests and limits so teams do not forget them.
Observe Resource Usage
kubectl top pods
kubectl top nodes
These commands rely on metrics-server being installed.
Why This Matters in Practice
If requests are too high, the scheduler may waste cluster capacity. If limits are too low, the app may be throttled or killed. Good tuning balances reliability and efficiency.
Think of requests as reserving seats on a train and limits as the maximum luggage weight allowed.
CPU Limit Effect
What usually happens when a container tries to use more CPU than its limit?
Memory Limit Effect
What usually happens when a container exceeds its memory limit?