How to Set Kubernetes Requests and Limits
Kubernetes requests tell the scheduler what a pod needs to be placed; limits cap what it can actually use. Without both, pods land anywhere and one noisy pod can OOM-kill its neighbors. Here's how to set them correctly.
Requests vs limits - what each field does
Every container in a pod can declare two resource fields:
- requests - the guaranteed minimum. The scheduler only places the pod on a node that has this much free. It also determines the pod's QoS class, which controls eviction order under memory pressure.
- limits - the hard ceiling. A CPU-throttled container keeps running but gets less CPU time. A container that exceeds its memory limit is OOM-killed immediately.
Without requests, the scheduler assumes the pod needs nothing and can over-pack the node.
Without limits, one runaway pod can consume every byte of RAM on the host.
Adding resources to a Deployment
Place the resources block inside the container spec, under containers[*]:
apiVersion: apps/v1
kind: Deployment
metadata:
name: worker
spec:
replicas: 1
selector:
matchLabels:
app: worker
template:
metadata:
labels:
app: worker
spec:
containers:
- name: worker
image: busybox:1.36
command: ["sleep", "86400"]
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
Apply it and confirm the values landed:
kubectl apply -f deployment.yaml
kubectl get deployment worker -o yaml | grep -A6 resources
Choosing good values
- CPU requests are in millicores (
m).100m= 0.1 vCPU. Start low (50-100m for a light worker) and raise once you have real usage data fromkubectl top pods. - Memory requests should match steady-state RSS, not peak. Check with
kubectl top podsor your metrics stack. - CPU limits - setting a CPU limit throttles burst performance. Many teams set
limits.cputo 2-4xrequests.cpuor omit it entirely and rely on requests for scheduling fairness. - Memory limits should be set - OOM kills are disruptive but recoverable;
a node running out of memory entirely is not. Set
limits.memoryto peak usage plus a safety margin (1.5-2x is common).
QoS classes
Kubernetes assigns a QoS class based on your resource config, which determines eviction priority under node pressure:
| Class | Condition | Evicted |
|---|---|---|
BestEffort |
No requests or limits at all | First |
Burstable |
Requests set but limits != requests | Second |
Guaranteed |
Requests == limits for all resources | Last |
Running with no resources at all means BestEffort - the pod is the first to go
when the node runs low on memory.
Want to try it hands-on? HeyDevJob gives you this exact setup in a live cloud workspace in your browser - edit it, run it, and see it work. Free, nothing to install.
Try it in a workspace →What you'll practice
- Adding cpu and memory requests and limits to a container spec
- Applying the updated Deployment and confirming the resource fields with kubectl
- Choosing requests and limits based on pod QoS class and eviction order
FAQ
What is the difference between Kubernetes requests and limits?
Requests are the guaranteed minimum the scheduler uses to decide where to place the pod. Limits are the hard ceiling - exceeding the memory limit triggers an OOM kill; exceeding the CPU limit causes throttling. Requests set the pod's QoS class; limits cap runtime usage.
What happens if I don't set resource requests in Kubernetes?
The scheduler treats the pod as needing zero resources (BestEffort QoS class), which means it can be over-packed on an already busy node and will be the first evicted under memory pressure. It also makes capacity planning impossible.
Should I set a CPU limit in Kubernetes?
Memory limits are strongly recommended - without them a single pod can OOM the node. CPU limits are more nuanced: they prevent bursting but also cause throttling even when the node has free CPU. Many teams set a cpu limit 2-4x the request, or skip it and rely on requests for scheduling fairness.
Keep learning
Learn it by doing. Open this in a live cloud workspace, make the change yourself, and keep a record of the work you can share.
Open the workspace →