Your Pods Keep Getting OOMKilled and Nobody Knows Why: Setting Kubernetes Requests and Limits That Match Reality

Kubernetes requests and limits explained with real resource tuning strategies. Learn why pods get OOMKilled and how to right-size workloads that hold under pressure.

Your Pods Keep Getting OOMKilled and Nobody Knows Why: Setting Kubernetes Requests and Limits That Match Reality

There is a particular kind of frustration that comes from watching a pod restart for the fourteenth time in a day with nothing but OOMKilled in the status column. The application logs look fine. The code has not changed. And yet Kubernetes keeps terminating containers like it has a personal grudge.

The problem is almost never the code. It is the gap between what you told Kubernetes your workload needs and what it actually consumes at runtime. That gap — between declared resource requests and limits and real-world behavior — is where most Kubernetes reliability issues take root. And closing it requires more than copying values from a blog post or a Helm chart default.

What OOMKilled Actually Means (and What It Does Not)

When Kubernetes marks a container OOMKilled, the Linux kernel's Out-Of-Memory (OOM) killer has terminated the process because it exceeded its memory limit. That is a hard boundary. Unlike CPU, which Kubernetes throttles when a container exceeds its CPU limit, memory cannot be compressed or paused. If a container tries to allocate beyond its memory limit, the kernel kills it. No negotiation.

This distinction matters. A pod that is CPU-throttled runs slowly but stays alive. A pod that hits its memory ceiling disappears. For stateful workloads or anything mid-transaction, that difference is the distance between a degraded experience and data loss.

But here is where it gets subtle: OOMKilled does not always mean your application has a memory leak. It can mean the limit was set too low for the workload's normal operating range. It can mean a traffic spike pushed heap usage past a threshold that was fine at baseline. It can mean the JVM, the Python runtime, or the Node.js garbage collector is holding memory in ways your static analysis never anticipated. The exit code tells you what happened. Understanding why requires looking at the resource configuration as a system, not just a pair of YAML fields.

Requests vs. Limits: Two Different Promises

Kubernetes resource configuration has two levers, and they serve fundamentally different purposes:

Requests: The Scheduling Contract

A resource request tells the Kubernetes scheduler how much CPU and memory to reserve for a container on a node. The scheduler uses requests — not limits — to decide where to place a pod. If you request 512Mi of memory, the scheduler finds a node with at least that much allocatable memory remaining. The container can use less than 512Mi at runtime, but the scheduler has set aside that capacity.

Setting requests too low is how you end up with overcommitted nodes. The scheduler thinks there is room. In reality, the containers on that node are all quietly using more than they declared. When total actual usage exceeds the node's physical memory, the kernel starts killing processes — and it picks the ones that have exceeded their requests by the widest margin.

Limits: The Hard Ceiling

A resource limit is the maximum a container is allowed to consume. For memory, exceeding this limit triggers the OOM kill. For CPU, the container gets throttled to its limit via CFS (Completely Fair Scheduler) bandwidth control.

Setting limits too tight causes OOMKilled restarts. Setting them too loose — or omitting them entirely — means a single misbehaving container can consume an outsized share of node resources and starve its neighbors. Both are real failure modes, and the right answer depends on the workload.

Why the Defaults Are Almost Always Wrong

Most teams inherit their resource values from one of three places: a Helm chart's values.yaml, a copy-paste from a tutorial, or a guess made under pressure during the first deployment. None of these reflect what your specific application does under your specific traffic patterns.

A Helm chart default of requests: 128Mi / limits: 256Mi might be reasonable for a lightweight sidecar proxy. It is wildly insufficient for a Spring Boot service with a default heap size of 512MB. And a blanket 4Gi limit on every pod in a namespace is how monthly cloud bills quietly double while nobody notices.

The foundational problem is that resource values are treated as configuration to fill in rather than engineering decisions to make. They deserve the same rigor as database schema design or API contracts, because they directly determine scheduling behavior, node density, autoscaling responsiveness, and failure modes under load.

How to Right-Size Kubernetes Workloads

Tuning resource requests and limits is an empirical process, not a theoretical one. Here is a grounded approach that holds across environments.

1. Observe Before You Declare

Before setting or adjusting resource values, you need actual usage data. At minimum, you need container-level memory and CPU metrics over a meaningful time window — not just steady state, but across peak traffic, batch processing, deployments, and garbage collection cycles.

Tools like Prometheus with cAdvisor metrics, or the Kubernetes Metrics Server feeding into Grafana dashboards, give you the visibility to answer specific questions: What is the P95 memory usage for this container over 7 days? What does CPU consumption look like during the morning traffic ramp? Does memory grow monotonically (possible leak) or oscillate around a stable range (normal GC behavior)?

If you do not have an observability stack in place, this is the step where resource tuning stalls. You cannot right-size what you cannot measure. Investing in metrics, alerting, and tracing infrastructure is the soil work that makes everything else possible.

2. Set Requests at the P95, Not the Average

A common mistake is setting requests at the average observed usage. The problem: average usage means 50 percent of the time the container needs more than that. When it does, and the node is fully committed, you get evictions or OOM kills under normal operating conditions.

Set memory requests at or near the 95th percentile of observed usage. This ensures the scheduler reserves enough capacity for the workload's realistic operating range, not just its calm moments. For CPU requests, the P90 or P95 during typical business hours is usually the right anchor — but CPU is more forgiving since throttling is non-fatal.

3. Set Memory Limits with Headroom, Not Hope

The memory limit should sit above the request — but how far above depends on the workload's behavior under pressure. For workloads with predictable, stable memory profiles (a compiled Go service, a stateless API gateway), a limit 20-30 percent above the P99 usage is often sufficient. For workloads with variable memory patterns (JVM-based services, Python ML inference, anything doing image processing), you may need 50 percent or more headroom above the P99.

The critical question is: what happens to this application's memory usage during an abnormal event? A traffic spike, a retry storm, a suddenly larger payload. If the answer is a controlled, bounded increase, tighter limits work. If the answer is an unpredictable spike, you either need generous limits or an architectural change to bound the consumption (streaming instead of buffering, for example).

4. Treat CPU Limits as Optional (Seriously)

This is a genuinely debated point in the Kubernetes community, and the right answer is nuanced. CPU limits cause throttling, which introduces latency. A container that could burst to 2 cores for 200 milliseconds during a request spike gets artificially constrained, adding tail latency that shows up in your P99 response times.

Many mature Kubernetes operators set CPU requests but omit CPU limits entirely for latency-sensitive workloads. This allows containers to burst when capacity is available while the requests still ensure fair scheduling. The trade-off: without CPU limits, a runaway process can temporarily starve other containers on the same node until the scheduler or a horizontal pod autoscaler reacts.

If your cluster runs mixed workloads — latency-sensitive APIs alongside batch jobs — consider using CPU limits on the batch workloads (which tolerate throttling) while leaving them off the APIs. This is where resource tuning becomes architecture, not just configuration.

5. Use LimitRanges and ResourceQuotas as Guardrails

Even with well-tuned individual workloads, namespace-level controls prevent a single misconfiguration from taking down the cluster. LimitRange objects set default requests and limits for containers that do not specify their own, and cap the maximum any single container can request. ResourceQuota objects cap total resource consumption per namespace.

These are not a substitute for per-workload tuning. They are a safety net — the kind of infrastructure-as-code guardrail that prevents the 3 AM page when someone deploys a new service with no resource spec at all.

6. Revisit After Every Significant Change

Resource profiles are not set-and-forget. A new feature that adds caching changes memory behavior. A library upgrade might alter GC characteristics. A shift from synchronous to asynchronous processing changes CPU and memory patterns simultaneously.

Build resource review into your deployment process. If your CI/CD pipeline runs load tests in a staging environment (and it should), compare the resource metrics from that run against your current requests and limits. Flag drift. Adjust before production, not after the OOMKilled alerts wake someone up.

The Vertical Pod Autoscaler: Helpful, but Not a Substitute for Understanding

The Kubernetes Vertical Pod Autoscaler (VPA) observes actual usage and recommends — or automatically applies — updated resource values. It is a valuable tool, especially for teams managing dozens or hundreds of workloads where manual tuning does not scale.

But VPA has real limitations. In Auto mode, it restarts pods to apply new resource values, which can cause disruption for workloads that do not handle restarts gracefully. Its recommendations are based on historical usage, which means it reacts to past patterns rather than anticipating new ones. And it cannot reason about the architectural context — whether a memory spike is normal burst behavior or an early sign of a leak that should be investigated rather than accommodated.

Use VPA recommendations as a starting point, not an endpoint. The judgment call — how much headroom, whether to set a CPU limit, how to balance density against resilience — still requires an engineer who understands the workload.

When Resource Tuning Is Really an Architecture Problem

Sometimes right-sizing resources does not fix the problem because the problem is not the resource configuration. If a service's memory grows without bound under sustained load, that is a leak or an unbounded queue, and no amount of limit adjustment will make it stable — you will just push the OOMKill to a later time.

If a workload needs 8Gi of memory to handle peak traffic, the question is not just what limit to set but whether the architecture is right. Could the work be distributed across more replicas with smaller footprints? Could an in-process cache be replaced with an external one? Could large payloads be streamed instead of buffered?

Resource tuning and software architecture are connected at the root. Treating them as separate disciplines — one for the platform team, one for the application team — is how organizations end up with technically correct YAML and fundamentally mismatched systems.

Related service: Cloud infrastructure and DevOps services in Tampa Bay — what we build, how we work, and what it costs.

Build the Foundation Before the Pressure Hits

Kubernetes resource tuning is not a one-time task. It is an ongoing engineering discipline that sits at the intersection of infrastructure design, application behavior, and operational observability. Getting it right means your workloads are scheduled efficiently, your nodes are not overcommitted, your autoscaling responds to real signals, and your pods stay alive when traffic surges instead of restarting in a loop.

Getting it wrong means silent cost waste on overprovisioned clusters, or worse — cascading OOMKills during the moments that matter most.

At FigTree Development, we architect Kubernetes environments that are grounded in real workload data, not guesswork. From observability stacks that surface resource drift before it causes incidents, to infrastructure-as-code configurations that enforce sane defaults across every namespace, we build container orchestration that holds under real pressure.

If your pods keep restarting and nobody on the team has time to dig into why, that is exactly the kind of problem a focused conversation can untangle. Book a free 20-minute discovery call and walk us through what you are seeing. We will help you understand whether the fix is resource tuning, architectural, or both — and what the path forward looks like.

Ready to Build?

Let's Plant Something Real.

Every project starts with a free 20-minute discovery call — no pitch, just a real conversation about what you're building and where the friction is.

Book a Discovery Call → ← Back to Blog
Start a Project →