Skip to content

InsightsPlatform Engineering

Requests, limits and the OOMKilled pod

What Kubernetes requests and limits actually do, why the defaults most teams copy cause throttling and evictions, and how to size workloads from real usage.

Published October 27, 20263 min read

Ask a team why a service has cpu: 500m and memory: 512Mi and the honest answer is usually that the last service had them. Requests and limits are among the most copied and least understood lines in a Kubernetes manifest. Getting them wrong shows up as one of three things: pods killed for memory, latency from CPU throttling, or a cluster paid for at three times the size it needs to be.

What each setting does

Requests are a reservation. The scheduler only places a pod on a node with enough unreserved capacity to cover its requests. CPU requests also set the pod's share of CPU when the node is busy.

Limits are a ceiling, and CPU and memory hit it in very different ways:

  • CPU over the limit is throttled. The container is paused for the rest of each scheduling period, even when the node has idle cores. Nothing crashes, but requests get slower.
  • Memory over the limit is killed. The kernel terminates the process, Kubernetes reports OOMKilled with exit code 137, and the container restarts.
kubectl describe pod checkout-7d9f8b6c4-x2kqp
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
    Restart Count:  4

Quality of service decides who is evicted

When a node runs short of memory, the kubelet evicts pods. The order depends on the quality-of-service class Kubernetes derives from requests and limits:

ClassWhenEvicted
GuaranteedEvery container has requests equal to limits, for both CPU and memoryLast
BurstableAt least one request or limit is set, but not GuaranteedAfter BestEffort, furthest above its memory request first
BestEffortNo requests or limits at allFirst

A pod with no resources set is the first to go when anything on the node misbehaves.

A sensible default

There are good reasons to deviate, but this is a solid starting point for most stateless services:

deployment.yaml (container resources)
resources:
  requests:
    cpu: 250m
    memory: 384Mi
  limits:
    memory: 384Mi
  • Memory request equals memory limit. The pod is never scheduled onto memory it cannot use, and it is never killed for using memory it was promised.
  • A CPU request, but no CPU limit. The service can use idle CPU on the node instead of being throttled while cores sit unused. This depends on every workload in the cluster setting honest CPU requests. Where that cannot be enforced, keep limits and watch throttling.

Size from data, not from the last service

Prometheus already has what you need. Over a week or more of normal traffic, look at:

peak memory per container (working set)
max_over_time(container_memory_working_set_bytes{namespace="checkout", container!=""}[7d])
95th percentile CPU per container
quantile_over_time(0.95, rate(container_cpu_usage_seconds_total{namespace="checkout", container!=""}[5m])[7d:5m])
share of CPU periods throttled
rate(container_cpu_cfs_throttled_periods_total{namespace="checkout"}[5m])
/
rate(container_cpu_cfs_periods_total{namespace="checkout"}[5m])

Set memory to the observed peak plus headroom for growth (20 to 30% is typical). Set CPU requests near the 95th percentile. If throttling stays above a few percent for a latency-sensitive service, raise or remove the CPU limit.

The Vertical Pod Autoscaler can do this analysis continuously. Run it with updateMode: "Off" and it publishes recommendations without restarting anything, which is a safe way to start.

Make the runtime aware of the limit

Many OOMKilled pods are runtimes that do not know about their container's limit:

  • Java: set -XX:MaxRAMPercentage (75 is a common value) so the heap leaves room for metaspace, threads and buffers.
  • Node.js: set --max-old-space-size below the limit; the default may not match the container.
  • Go: set GOMEMLIMIT slightly below the limit, so the garbage collector works harder before the kernel steps in.

What changes

With requests that match reality, the scheduler packs nodes properly and the autoscaler adds capacity when it is actually needed. Evictions stop surprising people. And the cluster bill reflects what the services use, not what was copied from a template two years ago.