Requests are not limits
A pod spec has two numbers for CPU and two for memory, and they do different jobs. Mixing them up is the usual cause of a node that looks idle while pods sit Pending, and of a container that gets killed while its dashboard says it had memory to spare.
What each field does
requests is a scheduling decision. The scheduler will not place a pod on a node unless the node’s remaining capacity covers the pod’s requests. Once the pod is running, the request is also a share: when the node is under pressure, CPU time is divided in proportion to requests.
limits is an enforcement decision, applied by the kubelet through cgroups, not by the scheduler.
For CPU, the limit is a ceiling on time. Cross it and the container is throttled. It is not killed. It gets slower, in a way that shows up as latency rather than as an error, which is why CPU throttling is so often missed.
For memory, the limit is a hard cap. Cross it and the container is OOMKilled. There is no throttling available. Memory it has allocated is memory it has.
So the four fields are four different statements:
- CPU request: how much the scheduler should reserve, and your weight under contention.
- CPU limit: how much time you may consume before being slowed down.
- Memory request: how much the scheduler should reserve.
- Memory limit: how much you may allocate before being killed.
QoS follows from this, it isn’t a separate setting
Kubernetes assigns a QoS class from those fields. You don’t set it.
If every container in the pod has CPU and memory requests equal to their limits, the pod is Guaranteed. It is the last class to be evicted when a node runs out of memory.
If a container sets a request or a limit but is not Guaranteed, the pod is Burstable. This is the common case, and it is a reasonable one: you reserve a floor, and you may burst above it until the node needs the room back.
If no container sets either, the pod is BestEffort. It is scheduled onto whatever is left, and it is the first thing evicted. A pod with no requests is not a small pod. It is an uncounted one, and it will be packed onto nodes that were already promised to someone else.
Setting them equal is a choice
Copying the same number into request and limit is tidy, and it buys Guaranteed. It also caps the container at its reservation. A process with a spiky CPU profile — startup, a garbage collection, a burst of requests — will throttle at a line it might have crossed for two seconds, on a node that had the idle cores to spare.
The opposite mistake is a limit far above the request, or no limit at all, on memory. The scheduler packs the node using requests. The kernel only finds out the real usage when the container allocates. If five pods each requested 256Mi and each can grow to 2Gi, the node was scheduled as if it had room, and it doesn’t. That is the OOM you cannot see coming from the pod spec alone.
A workable default, until you have measurements:
- Memory request near the steady-state usage, limit a bounded step above it, sized for the spike you have actually seen. An unbounded limit is a bet that this pod will be polite.
- CPU request near steady state. Set a CPU limit only if you have a reason to protect neighbours from this process. If you set one, watch throttling, not just usage. Usage under a limit can be 50% while the container is throttled every period.
- Never leave a production workload as BestEffort. The cost of a guess is lower than the cost of an invisible tenant.
Then measure. kubectl top is a spot check, not a profile. The number you want is the usage over a week, including the deploy, the traffic spike, and the backup. The request should sit near the sustained line. The limit should sit above the worst sustained spike, not above the theoretical maximum.
You might also be interested
Pin the chart version, and never reuse the tag
The failure mode where git is right, the cluster is old, and nobody can tell from the commit.
Read the diff that will actually ship
The chart changed. The cluster will apply something else. A short habit for reviewing GitOps changes.
Why this site is a static site
I moved the blog off WordPress onto Astro. What that actually changes, and what I gave up on purpose.