Almost every Kubernetes problem that looks like “my app is slow” or “my Pod keeps restarting” comes back to two small fields in the Pod spec: requests and limits. They decide where a Pod can run, how much CPU it gets when the node is busy, when it gets killed for using too much memory, and which Pods the kubelet removes first when a node runs short. Kubernetes also turns these values into a Quality of Service (QoS) class for every Pod.
This guide explains requests, limits and QoS classes in plain terms, using the official Kubernetes documentation as the reference. It also covers in-place Pod resize, which became stable in Kubernetes v1.35, so you can change CPU and memory on a running Pod.
Requests and limits in one minute
You set requests and limits per container, under spec.containers[].resources. The most common resources are cpu and memory. Kubernetes also supports ephemeral-storage, hugepages-<size> and extended resources such as GPUs exposed by device plugins.
- Request: the amount the container is planned to need. The scheduler uses it to pick a node, and the kubelet reserves at least this much for the container.
- Limit: the most the container is allowed to use. The kubelet and the container runtime enforce it, and on Linux the kernel does the actual work through cgroups.
A container can use more than its request if the node has spare capacity. It cannot go above its CPU limit, and if it goes above its memory limit it can be killed. One detail surprises many people: if you set a limit but no request, and nothing like a LimitRange adds a default, Kubernetes copies the limit and uses it as the request.
Here is the two container example from the Kubernetes docs. Each container requests 250m CPU and 64Mi of memory, with a limit of 500m CPU and 128Mi.
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
- name: log-aggregator
image: images.my-company.example/log-aggregator:v6
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Pod-level resources are also available (beta since v1.34 and enabled by default). With them you set spec.resources for the whole Pod, and containers without their own values share that budget. This is handy for Pods with many small sidecars.
How Kubernetes enforces CPU and memory
The two resources behave very differently, and this is the part worth remembering.
Scheduling uses requests, not real usage
The scheduler only places a Pod on a node if the sum of requests on that node stays within the node’s allocatable capacity. It does this even when actual usage on the node is low. That is why a Pod can stay Pending with a FailedScheduling event such as “insufficient cpu” on a cluster that looks idle. For the other placement rules, see our guide to Kubernetes Pod scheduling.
CPU is throttled
The CPU request works as a weight. When containers compete for CPU, the one with the bigger request gets more CPU time. The CPU limit is a hard ceiling: during each time slice the kernel checks usage and pauses the container if it has used its share. The container is slowed down, not killed. Runtimes do not terminate containers for using too much CPU.
Memory is killed
Memory cannot be throttled the same way. If a container goes above its memory limit, the kernel’s out of memory (OOM) handling usually stops a process in that container. If that process is PID 1, the kubelet restarts the container. In kubectl describe pod you will see Last State: Terminated with Reason: OOMKilled and exit code 137.
There is a second path to losing a Pod. If a container uses more memory than its request and the node itself runs short, the kubelet can evict the whole Pod. That is node-pressure eviction, and QoS classes decide the order.
CPU and memory units
- CPU is measured in cores.
1means one physical or virtual core.0.5and500m(500 millicpu) are the same. The smallest step is1m, so the millicpu form makes invalid values easier to spot. - Memory is measured in bytes. Use power-of-two suffixes like
MiandGi, or decimal suffixes likeMandG. - Watch the case.
400mof memory means 0.4 bytes, not 400 megabytes. You almost always want400Mi.
The three QoS classes
Kubernetes assigns every Pod one QoS class based on its requests and limits. You cannot set the class directly; it follows from the values you choose. It is stored in status.qosClass and stays the same for the life of the Pod.
- Guaranteed: every container has CPU and memory requests and limits, all greater than zero, and for each container the request equals the limit (or the Pod uses Pod-level resources with equal requests and limits). These Pods are the last to be evicted and can use exclusive CPUs with the static CPU manager policy.
- Burstable: the Pod is not Guaranteed, but at least one container has a CPU or memory request or limit. These Pods get a lower bound from their requests and can use more when the node has room.
- BestEffort: no container has any CPU or memory request or limit. These Pods use whatever is left over, and the kubelet prefers to evict them first.
When a node is under resource pressure, the kubelet first looks at Pods whose usage is above their requests, then ranks by Pod priority and by how far usage exceeds requests. In practice that means BestEffort goes first, then Burstable Pods that are over their requests, and Guaranteed Pods last. A Pod that stays within its requests is rarely the one removed.
Two more points from the docs: the scheduler does not consider QoS class when it chooses Pods to preempt, and on Linux nodes with cgroup v2 the Memory QoS feature (beta in v1.37) can use the QoS class to set memory throttling and protection, but only when you configure it in the kubelet.
Hands-on: create a Guaranteed Pod and check its class
Prerequisites: a working cluster (kind, minikube or any test cluster) and kubectl configured to talk to it. These steps come from the official Configure Quality of Service for Pods task.
Create a namespace for the exercise:
kubectl create namespace qos-example
The example Pod sets CPU and memory requests equal to the limits, so it qualifies as Guaranteed:
apiVersion: v1
kind: Pod
metadata:
name: qos-demo
namespace: qos-example
spec:
containers:
- name: qos-demo-ctr
image: nginx
resources:
limits:
memory: "200Mi"
cpu: "700m"
requests:
memory: "200Mi"
cpu: "700m"
Apply it and inspect the Pod:
kubectl apply -f https://k8s.io/examples/pods/qos/qos-pod.yaml --namespace=qos-example
kubectl get pod qos-demo --namespace=qos-example --output=yaml
Look for qosClass under status in the output. Try removing the limits or making the request lower than the limit in your own copy, and the class changes to Burstable. When you are done, clean up:
kubectl delete namespace qos-example
To see how much of a node is already reserved, run kubectl describe nodes <node-name> and read the Allocatable and Allocated resources sections. Total limits can be above 100 percent, because limits may be overcommitted while requests may not.
Changing resources on a running Pod
The classic way to change resources is to update the Pod template in a Deployment or StatefulSet and let the controller roll out new Pods. That still works everywhere. Since Kubernetes v1.35, in-place Pod resize is stable: you change CPU and memory on a running container through the Pod’s resize subresource, often without a restart.
You control restarts per resource with resizePolicy. NotRequired (the default) applies the change live, and RestartContainer restarts the container, which suits apps that cannot adjust memory at runtime.
resizePolicy:
- resourceName: cpu
restartPolicy: NotRequired
- resourceName: memory
restartPolicy: RestartContainer
This command from the official resize task raises CPU to 800m on a Pod named resize-demo. It needs kubectl v1.32 or later:
kubectl patch pod resize-demo -n qos-example --subresource resize --patch \
'{"spec":{"containers":[{"name":"pause", "resources":{"requests":{"cpu":"800m"}, "limits":{"cpu":"800m"}}}]}}'
Keep the limits in mind. Only CPU and memory can be resized, a resize cannot change the Pod’s QoS class, Windows Pods are not supported, and requests and limits cannot be removed once set. If the node cannot fit the new values, the Pod gets a PodResizePending condition with reason Infeasible or Deferred. The Vertical Pod Autoscaler can suggest or apply values for you; we cover it in Kubernetes autoscaling explained.
Practical tips for choosing values
- Always set requests. Without them the scheduler has no idea what a Pod needs, and the Pod lands in BestEffort, first in line for eviction.
- Set a memory limit. A container without one can grow until the node runs out. Memory backed
emptyDirvolumes also count against memory, and without a limit orsizeLimitthey can fill the node. - Use Guaranteed for critical, steady workloads such as databases, and Burstable for most stateless services.
- Base numbers on measurements, not guesses. Start from observed usage in your monitoring tools, then adjust. Repeated OOMKilled restarts mean either a leak or a limit that is too low.
- Give namespaces defaults. A LimitRange can fill in requests and limits for containers that skip them, and a ResourceQuota caps the total. Our guide to Kubernetes quotas and LimitRanges walks through both.
Key takeaways
- Requests drive scheduling and CPU share; limits set the ceiling.
- Going over a CPU limit means throttling. Going over a memory limit can mean an OOM kill.
- If you set only a limit, Kubernetes uses it as the request too.
- QoS classes (Guaranteed, Burstable, BestEffort) come from your values and set the eviction order under node pressure.
- In-place Pod resize is stable since v1.35, but it cannot change a Pod’s QoS class.
- Use LimitRange, ResourceQuota and real usage data to keep values sensible across teams.
Sources
Resource Management for Pods and Containers, Pod Quality of Service Classes, Configure Quality of Service for Pods, Resize CPU and Memory Resources assigned to Containers, Node-pressure Eviction, Limit Ranges and Resource Quotas, all on kubernetes.io.
