Kubernetes Requests vs. Limits: Preventing Resource Starvation
From the publisher’s feed, collected in the ZeroLabs newsroom.
(Clear, comparison-driven, matches the exact terminology beginners search when they hit scheduling or OOM issues.)Two numbers in your YAML decide whether your Pod gets scheduled fairly, throttled quietly, or killed outright. Most people only learn what they mean after one of those things already happened.Kubernetes Requests vs Limits Explained — Prevent OOMKilled and Noisy NeighborsCPU and memory requests and limits decide how Kubernetes schedules Pods, throttles them, and decides who gets killed when a Node runs low on resources. Here’s how they actually work, with real YAML examples and OOMKilled debugging steps.At some point, almost every Kubernetes user gets the same unpleasant surprise: kubectl get pods shows a Pod with a status of OOMKilled, restart count ticking upward, and no obvious explanation for why an application that worked fine yesterday suddenly got terminated by the system it's running on. The honest answer, most of the time, traces back to two numbers that were either never set, or set without really understanding what they do: requests and limits.These two fields don’t look like much in a YAML file — a few lines under resources, easy to skip or copy-paste from a tutorial without thinking too hard about them. But they're doing genuinely important work: deciding which Node your Pod gets scheduled onto, how it behaves when a machine gets crowded, and — in the worst case — whether it survives or gets forcibly killed when memory runs low. Skipping them, or setting them carelessly, is one of the most common ways a Kubernetes cluster ends up unstable in ways that feel random but absolutely aren't.Requests tell the scheduler what a Pod needs to run comfortably. Limits tell the system what a Pod is never allowed to exceed. Confusing the two — or setting neither — is how clusters end up with Pods quietly starving each other.What “Requests” Actually DoA request is the amount of CPU and memory a container is guaranteed to get, and — just as importantly — it’s the number Kubernetes’s scheduler uses to decide which Node a Pod is even allowed to run on in the first place.Here’s the mechanism, made concrete: when you create a Pod, the scheduler looks at every Node in the cluster and asks, “does this Node have enough unreserved capacity to cover this Pod’s requests?” If a Node has 4 CPU cores total, and other Pods already running on it have requested 3.5 of those cores, a new Pod requesting 1 full core won’t be scheduled there — even if, in practice, those other Pods are barely using half of what they requested at that exact moment. The scheduler works off requested amounts, not actual real-time usage.resources: requests: cpu: "250m" memory: "256Mi"That 250m means 250 millicores — a quarter of a single CPU core. Kubernetes measures CPU in these fractional units specifically because most containers don't need a whole core to themselves, and this lets scheduling be far more precise than "one full core or none."Key takeaway: Requests aren’t a soft suggestion — they’re the exact number the scheduler uses to decide where your Pod is allowed to live, regardless of how much it actually ends up using once running.What “Limits” Actually DoA limit is the maximum amount of CPU and memory a container is allowed to consume, full stop — and what happens when a container tries to exceed it differs meaningfully between CPU and memory, which is a distinction that trips up a lot of people.resources: limits: cpu: "500m" memory: "512Mi"For CPU, exceeding the limit doesn’t crash anything — the container simply gets throttled, meaning it’s forcibly slowed down to stay within its ceiling. Your application keeps running, just slower than it would otherwise, which can show up as mysteriously degraded performance that’s easy to misdiagnose as an application bug rather than a resource ceiling being hit.For memory, exceeding the limit is far less forgiving: the container gets killed outright, with the status OOMKilled ("Out Of Memory Killed") showing up in kubectl describe pod. Unlike CPU, memory genuinely can't be throttled the same way — a process either has the memory it needs or it doesn't — so Kubernetes's only real option once a container crosses its memory limit is to terminate it and, if it's managed by a Deployment, let the self-healing mechanism from earlier in this series restart it.CPU limits slow you down. Memory limits kill you. That asymmetry alone is worth remembering the next time you’re deciding how tightly to set either one.Key takeaway: A CPU limit breach is a performance problem. A memory limit breach is a Pod-killing event. Treat the two very differently when deciding how conservatively to set them.The Four Combinations, and What Each One Actually MeansSetting requests and limits isn’t all-or-nothing — Kubernetes actually assigns every Pod to one of three Quality of Service (QoS) classes based on how you’ve configured these values, and that classification directly affects what happens to your Pod under resource pressure.This matters far more than it looks like on paper. When a Node genuinely runs low on memory, Kubernetes doesn’t evict Pods randomly — it evicts BestEffort Pods first, then Burstable Pods, and only reaches Guaranteed Pods as an absolute last resort. If your production database is running with no resource configuration at all — BestEffort by default — it's sitting at the very front of the eviction line the moment that Node gets tight on memory, regardless of how important that workload actually is to you.Key takeaway: Leaving requests and limits unset isn’t a neutral choice — it silently puts your Pod in the worst possible position when a Node runs into resource pressure.The Noisy Neighbor Problem, Explained Properly“Noisy neighbor” is the term for exactly the scenario requests and limits exist to prevent: one Pod consuming far more than its fair share of a Node’s resources, starving every other Pod sharing that same machine, even though those other Pods did nothing wrong.Picture a Node with 8 CPU cores, running four Pods, none of which have any CPU limit set. Under normal conditions, everything’s fine — each Pod uses a modest, reasonable amount of CPU. Then one of those Pods hits a traffic spike, or gets stuck in an inefficient loop due to a bug, and starts consuming far more CPU than usual. With no limit in place, nothing stops it from consuming the majority of that Node’s available CPU — and the other three Pods, innocent bystanders sharing the same physical machine, suddenly find themselves starved of CPU time they need, through no fault of their own.This is precisely why setting limits isn’t just about protecting a container from itself — it’s about protecting everything else sharing that Node from a single misbehaving neighbor. A limit acts as a hard ceiling that keeps one Pod’s bad day from becoming everyone’s bad day.Key takeaway: Limits aren’t primarily about self-discipline for one Pod — they’re a shared-resource protection mechanism for every other Pod unlucky enough to be scheduled on the same Node.Debugging an OOMKilled PodWhen you hit OOMKilled in practice, here's the actual sequence worth running through, rather than immediately assuming the memory limit was simply "too low."kubectl describe pod This shows real-time CPU and memory usage, which you can compare directly against the requests and limits defined in your Pod spec. If actual usage is consistently pushing right up against the memory limit, you're looking at one of two real explanations, and it's worth being honest about which one applies: either the limit is genuinely set too low for what this application legitimately needs, or the application has a memory leak that's slowly climbing toward that ceiling over time regardless of what the limit is set to. Bumping the limit fixes the first case. It only delays and disguises the second.Key takeaway: An OOMKilled Pod has two very different possible causes — an undersized limit, or a genuine memory leak — and raising the limit only actually fixes one of them.A Practical Starting PointFor teams unsure where to even begin, a reasonable, commonly used starting pattern is setting requests based on typical observed usage, and limits somewhat higher to allow for legitimate bursts, rather than setting both to identical values everywhere by default.resources: requests: cpu: "250m" memory: "256Mi" limits: cpu: "500m" memory: "512Mi"This gives a Pod room to burst up to double its baseline under real load, while still guaranteeing the scheduler reserves a sensible minimum for it on whatever Node it lands on. It’s a starting point, not a universal formula — the right numbers genuinely depend on what your specific application actually does, and there’s no substitute for watching real usage with kubectl top (or a proper metrics pipeline) over time and adjusting based on what you actually observe, rather than guessing once and never revisiting it.Why This Matters More as Clusters Get BusierOn a quiet development cluster with plenty of spare capacity, skipping requests and limits often goes completely unnoticed — there’s enough slack everywhere that nothing actually competes for anything. The real cost shows up precisely when it’s most inconvenient: production, under real load, when multiple workloads are genuinely competing for finite Node capacity at the same time.This is a big part of why experienced teams treat requests and limits as a required part of any Deployment YAML, not an optional tuning step reserved for “later, once we scale.” The moment you actually need them to be correct is exactly the moment you’re least able to afford figuring it out for the first time.Key takeaway: Requests and limits matter most exactly when your cluster is under real pressure — which is the worst possible time to be setting them for the first time.The Habit Worth BuildingThe next time you write a Deployment YAML, treat the resources block the same way you'd treat any other required field, not an optional afterthought worth skipping until something breaks. Ask two concrete questions for every container: what does this realistically need to run comfortably under normal load (your request), and what's the absolute most it should ever be allowed to consume before it's actively hurting something else on the same Node (your limit).Answering those two questions honestly, for every workload you deploy, is a small amount of upfront effort that quietly prevents an entire category of the most confusing, hardest-to-diagnose production incidents Kubernetes clusters run into — the ones where nothing in your application logs looks wrong, because the actual cause was never really about your code at all.Have you had a noisy-neighbor incident or an OOMKilled surprise that taught you this the hard way — and what did you change afterward?Kubernetes Requests vs. Limits: Preventing Resource Starvation was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.