What are resource requests and limits in Kubernetes?
BeginnerConceptContainers & Kubernetes basics
Answer
In one line: Requests are the CPU and memory a container is guaranteed and are used by the scheduler to place pods; limits are the maximum a container is allowed to use.
Example:
resources:
requests:
cpu: "250m" # a quarter of a CPU core
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
Requests
- The scheduler only places a pod on a node that has enough unreserved capacity for its requests.
- Used by the Horizontal Pod Autoscaler to calculate utilisation percentages.
Limits
- CPU over the limit → the container is throttled (slowed down), not killed.
- Memory over the limit → the container is OOMKilled (killed and restarted). You'll see
OOMKilledinkubectl describe pod.
QoS classes (based on requests and limits):
- Guaranteed — requests = limits for CPU and memory. Last to be evicted.
- Burstable — requests set lower than limits.
- BestEffort — nothing set. First to be evicted when a node runs short of memory.
Why setting them matters:
- No requests → the scheduler packs too many pods on a node; they fight for resources.
- Requests too high → wasted, expensive nodes sitting mostly idle.
- Memory limit too low → constant OOMKills and restarts.
- CPU limits too tight → throttling and slow responses (many teams set CPU requests but leave CPU limits generous or unset).
How to choose values:
- Look at real usage in Prometheus/Grafana or
kubectl top pods. - Use the Vertical Pod Autoscaler in recommendation mode.
- Set memory limit with some headroom above normal peak usage.
- Use LimitRange and ResourceQuota to enforce defaults and caps per namespace.
Tip for interviews: explain throttling vs OOMKill — it's a classic question and a common real-world issue.
More on Containers & Kubernetes basics
What is the difference between a Docker image and a container?BeginnerWhat makes a good Dockerfile? Give some best practices.BeginnerWhat is Kubernetes, and why do we need it?BeginnerExplain the Kubernetes architecture in simple terms.BeginnerWhat are Pods, Deployments and Services in Kubernetes?BeginnerWhat are liveness, readiness and startup probes?Beginner