Chasing OOMKills in Kubernetes

Picture of me

Author: Baden

November 26, 2026

An OOMKill is one of the most common ways a Kubernetes pod dies, and one of the easiest to misread. The pod restarts, comes back healthy, and the evidence of what happened is spread across pod status, events, container logs and the node's kernel log.
I hit a textbook case recently. On one of the production clusters I run, the Loki chunks-cache pods were being OOM-killed about three times a day. Those pods are memcached instances sitting in front of object storage, so every restart threw away a warm cache and sent more reads back to the bucket. Nothing was down, which is exactly why this kind of problem can run for months.
This post walks through how I tracked it down, step by step, and turns it into a process you can reuse on any OOMKill.

Step 1: Confirm it really is an OOMKill

A climbing restart count is the first clue, but restarts have many causes: failed liveness probes, crashes, bad config. Before tuning anything, confirm what killed the container.
kubectl -n loki get pods | grep chunks-cache kubectl -n loki describe pod loki-chunks-cache-0 | grep -A6 "Last State"
Query the loki pods.

An OOMKill looks like this in the container's last state:
Last State: Terminated Reason: OOMKilled Exit Code: 137
What the OOMKill will look like with its error.

Exit code 137 means the process received SIGKILL (128 + 9). Together with Reason: OOMKilled, it tells you the container crossed its memory limit and the kernel killed it. Exit code 137 on its own isn't proof, since anything that sends SIGKILL produces it, so look for the reason too.
To check many pods at once, pull the last termination reason straight from the status:
kubectl -n loki get pods -o
One caveat: Last State only remembers the most recent termination. If a pod restarted for a different reason since, the OOMKill is gone from its status, and you'll need the other sources in the next step.

Step 2: Read the logs, knowing what they can't show

The first instinct is kubectl logs, and it's worth doing, but with the right flag. The current container is the fresh one, so you want the one that died:
kubectl -n loki logs loki-chunks-cache-0 -c memcached --previous --tail=50
Don't expect an error message at the end. SIGKILL can't be caught, so the process gets no chance to log anything. An OOMKilled container's log usually just stops mid-stream. That silence is itself a clue: a crash or a failed probe tends to leave something behind, an OOMKill doesn't.

The real record of the kill is in the node's kernel log. Find the node, then search there:
# Find the node kubectl -n loki get pod loki-chunks-cache-0 -o wide # on that node journalctl -k --since "2 days ago" | grep -iE "out of memory|killed process"
Make sure to run the second command on the correct node.

The wording tells you which kind of OOM it was:
• Memory cgroup out of memory: Killed process ... (memcached) means the container hit its own limit. The node was fine. This is the OOMKilled you see in pod status, and it was my case.
• Out of memory: Killed process ... without the cgroup part means the whole node ran out of memory and the kernel picked a victim. That points at overcommitted nodes, not one container.
There's a third, gentler outcome: eviction. Before the kernel steps in, the kubelet can evict pods when a node is under memory pressure. Evicted pods show Status: Failed with Reason: Evicted and a message about the node being low on memory, rather than OOMKilled. If you run RKE2, the kubelet's own log lives at /var/lib/rancher/rke2/agent/logs/kubelet.log, and recent events show evictions too:
kubectl -n loki get events --sort-by=.lastTimestamp | grep -iE "oom|evict"
Events only last about an hour by default, so if the kill happened overnight, the kernel log is your best witness.

Step 3: Measure real memory use against the limit

Once you know it's a limit OOM, put two numbers side by side: what the container is allowed, and what it actually uses.
# the limit kubectl -n loki get pod loki-chunks-cache-0 \ -o jsonpath='{range .spec.containers[*]}{.name}{"\t"}{.resources.limits.memory}{"\n"}{end}' # current use kubectl -n loki top pods --containers | grep chunks-cache
Compare the memory limit with what the pod is actually using.

kubectl top is a snapshot, so the shape over time matters more than any single reading. If you have Prometheus, graph container_memory_working_set_bytes for the container against its limit. The shape usually tells you which kind of problem you have:
• A steady climb to the limit, a kill, then the same climb again is a sawtooth. Something is growing on purpose or leaking. A cache filling its budget looks exactly like this.
• Flat, then a sudden spike points to a burst: a big query, a large request, a batch job.
• Close to the limit from the start means the limit was simply set too low for normal operation.
My chunks-cache fit the first pattern: killed about every eight hours, day after day. That ruled out a one-off spike and told me something inside memcached was growing until it hit the wall.

Step 4: Find the config that fights the limit

Here's the step most OOMKill investigations skip. Many programs manage their own memory budget, and that budget is set somewhere completely separate from the Kubernetes limit. If the two disagree, the program will happily grow to its budget and the kernel will kill it every time.
Check the arguments the container actually runs with:
kubectl -n loki get pod loki-chunks-cache-0 \ -o jsonpath='{.spec.containers[?(@.name=="memcached")].args}'
Show the arguments memcached was started with.

In my case the answer was right there. memcached was started with a cache size of 8192 MB, while the container's memory limit was 4Gi. memcached fills its cache up to the size it's given, so it was guaranteed to cross the limit. It wasn't a leak and it wasn't load. It was two settings, in two places, that had never been checked against each other.
memcached isn't special here. The same mismatch shows up in:
• JVM apps: -Xmx or MaxRAMPercentage set higher than the limit allows, forgetting the memory the JVM uses outside the heap.
• Go services: no GOMEMLIMIT, so the garbage collector doesn't know a limit exists.
• Node.js: --max-old-space-size above the container limit.
• Redis: maxmemory unset or larger than the limit.
• Databases: buffer and cache settings such as PostgreSQL's shared_buffers sized for a VM, not a pod.
If an app has a memory knob of its own, its value belongs in the same review as the pod's resources.

Step 5: Fix it, then prove the fix

There are two ways to resolve a mismatch: shrink the app's budget to fit the limit, or raise the limit to fit the budget plus overhead. I wanted the 8 GB cache, so I raised the memory limit to 10Gi and left the cache size alone.
I applied it as a live patch on one cluster first, then waited. "It hasn't restarted yet" isn't proof for a problem that struck every eight hours, so I gave it four days and checked three things:
kubectl -n loki get pods | grep chunks-cache kubectl -n loki top pods | grep chunks-cache kubectl -n loki describe pods -l app.kubernetes.io/component=memcached-chunks-cache | grep -A4 "Last State"
Check restarts, memory use and the last termination after the fix.

The results after four days and six hours:
• Restarts: about 3 per day before, 0 after.
• Memory per pod: climbing to the 4Gi limit before, flat at about 8.1 GiB after.
• Last State: OOMKilled before, empty with no terminations after.
The flat memory line was the most reassuring part. Two readings minutes apart were identical, which meant the cache had filled to its 8192 MiB budget and was now evicting old entries instead of growing.
It also corrected my guess about overhead. memcached used about 90 MiB on top of its cache, far less than I'd allowed for. That leaves roughly 1.9 GiB of headroom under the 10Gi limit, enough that I could trim to a 9Gi limit later. For now the margin is cheap insurance against connection spikes.
With the fix proven on one cluster, the same values change goes out to my other clusters through Fleet, so they stop restarting too.

An OOMKill checklist to keep

1. Confirm the cause. Look for Reason: OOMKilled and exit code 137 in Last State, not just a rising restart count.
2. Read the previous container's logs. Use kubectl logs --previous, and expect them to stop abruptly with no error.
3. Check the node's kernel log. Memory cgroup out of memory means the container's own limit; a plain Out of memory means the whole node.
4. Rule out eviction. Reason: Evicted is node memory pressure, a different problem with a different fix.
5. Graph usage against the limit. A sawtooth, a spike and a flat-but-too-high line each point somewhere different.
6. Find the app's own memory setting. Cache sizes, heap sizes and memory limits inside the app must fit inside the container limit, with room for overhead.
7. Fix one place, prove it over time, then roll out. Wait several cycles of the old failure interval before calling it fixed.
In conclusion, my Loki cache had been dying three times a day because two numbers in two different places disagreed. No log line said so directly. Putting the kill record, the usage graph and the app's config side by side made it obvious.