If you run applications on Kubernetes, the CPU and memory requests and limits on each container decide where it runs, how much power it gets and whether it survives a busy moment. A request is the amount the scheduler (the part of Kubernetes that picks a node for each Pod) reserves for the container. A limit is the ceiling it can never pass. When they are set badly, you see Pods stuck in Pending or containers killed with OOMKilled (out of memory). You can also get apps that crawl because the kernel holds back their CPU time, which is called throttling.
The sections below explain what each setting does for CPU and for memory, and how Kubernetes uses them to give every Pod a quality-of-service (QoS) class. That class decides which Pods get evicted first when a node runs short. You will also see how to tell an OOMKill from CPU throttling. The last part covers LimitRange and ResourceQuota. These two objects set defaults and caps per namespace (the slice of the cluster a team or app works in), so one workload cannot use up everything.
How to verify
What’s set on every workload, and what each Pod was placed against:
kubectl get pods -A -o custom-columns=NS:.metadata.namespace,POD:.metadata.name,QOS:.status.qosClass
kubectl describe pod web-7fdb6f9b56-2vp8x | sed -n '/Containers:/,/Conditions:/p'
kubectl top pods -A
For one container, the resources block is the source of truth:
kubectl get deploy web -o jsonpath='{.spec.template.spec.containers[*].resources}'
When a Pod gets killed, the reason is on the previous container’s status:
kubectl get pod web-7fdb6f9b56-2vp8x -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}'
# OOMKilled ? Error ? Completed ?
What’s happening
A request is what the scheduler reserves on the node. It’s the floor — a guaranteed allocation that no eviction or noisy neighbour can take below this value for sustained periods. A limit is the ceiling — exceeding it triggers very different actions depending on the resource.
CPU. CPU is compressible. A CPU request reserves CFS shares; a CPU limit caps usage by way of CFS quota (every 100 ms slice, the container gets at most limit * 100 ms). Hit the limit and you’re throttled, not killed — but throttling is severe and often invisible in metrics until you look at container_cpu_cfs_throttled_periods_total. Some teams omit CPU limits entirely on latency-sensitive workloads; the trade-off is unbounded CPU usage, which can starve neighbours unless you also set sensible requests.
Memory. Memory is non-compressible. A memory request reserves space the scheduler counts against node capacity. A memory limit is enforced by the kernel; exceed it and the kernel OOMKills the container. There is no “throttling” for memory — you get the memory you allocated or your process dies.
Kubernetes derives a QoS class from the values: Guaranteed (request == limit for both CPU and memory on every container), Burstable (at least one request set but not Guaranteed), BestEffort (no requests or limits). Under node pressure, the kubelet evicts BestEffort first, Burstable next, Guaranteed last. Guaranteed Pods are also pinned to CPUs when the static CPU manager policy is on.
A LimitRange sets defaults and per-Pod/per-Container minimums and maximums in a namespace — useful so naive workloads don’t ship with no requests at all. A ResourceQuota caps the total of requests, limits, and object counts a namespace can hold.
The procedure
-
Start with realistic requests measured from running workloads, not picked from the air. Run for a week, look at p95 and p99 utilisation, set requests at p95 with limits at 2-3x for non-latency-critical work:
resources: requests: cpu: "300m" memory: "512Mi" limits: cpu: "1000m" memory: "768Mi" -
Skip CPU limits on latency-sensitive paths when you have room. The kernel does not throttle a container without a CPU limit, but a request still reserves the share the container is guaranteed:
resources: requests: { cpu: "500m", memory: "512Mi" } limits: { memory: "768Mi" } # no cpu limit -
Pin a critical workload to Guaranteed QoS so it survives node pressure and (with the CPU manager) gets pinned cores:
resources: requests: { cpu: "2", memory: "4Gi" } limits: { cpu: "2", memory: "4Gi" } -
A LimitRange that catches naive workloads without requests. New Pods in this namespace inherit defaults; oversized Pods are rejected:
apiVersion: v1 kind: LimitRange metadata: name: defaults namespace: team-payments spec: limits: - type: Container default: cpu: "500m" memory: "512Mi" defaultRequest: cpu: "100m" memory: "128Mi" max: cpu: "4" memory: "8Gi" -
A ResourceQuota that caps a namespace at sensible aggregate totals:
apiVersion: v1 kind: ResourceQuota metadata: name: payments-quota namespace: team-payments spec: hard: requests.cpu: "16" requests.memory: "32Gi" limits.cpu: "32" limits.memory: "64Gi" count/pods: "100" -
Diagnose an OOMKill.
kubectl describe podshows the last terminated state; node-leveldmesggives the kernel’s view:kubectl describe pod web-7fdb6f9b56 -n team-payments | grep -A2 'Last State' kubectl debug node/ip-10-0-0-12 -it --image=ubuntu -- chroot /host dmesg | grep -i oom-kill | tail -
Diagnose CPU throttling. The Prometheus metric is
container_cpu_cfs_throttled_periods_total / container_cpu_cfs_periods_total; values above 0.05 mean meaningful throttling:rate(container_cpu_cfs_throttled_periods_total{container="web"}[5m]) / rate(container_cpu_cfs_periods_total{container="web"}[5m])
Common pitfalls
- Setting CPU limits very close to requests gives you throttling at the typical workload — the kernel enforces the limit every 100 ms slice; leave headroom or omit the limit.
- A memory limit lower than the actual working set OOMKills the container on the first traffic spike — the “I’ll start tight and watch” approach is fine for staging, painful for production.
- BestEffort Pods (no requests) compete unfairly for node resources and are first to be evicted — don’t ship them.
- Java/JVM memory limits need
-XX:MaxRAMPercentageor an explicit-Xmxaligned to the container limit; without that, the JVM sizes against the host’s memory and gets OOMKilled when it grows past the container ceiling. LimitRangeonly applies to objects created after it exists — it doesn’t retroactively patch existing Pods; combine it with a policy admission controller for enforcement.
We operate workload sizing for clients with measured requests, conservative limits per QoS, LimitRange defaults in every namespace, and alerts on both OOMKill rate and CFS throttle ratio. See /en/services/managed-operations/.