Node
OOMKilled
Memory limits in practice
A container crosses its memory limit and the kernel kills it. See where the limit lives - a single cgroup file - who does the killing, and who reports it. The whole journey of one web Pod that tried to load a 300 MB report with a 256 Mi limit: allocate, charge, exceed, SIGKILL, 137.
- Pod
- web-…-p8m4z · node-2 · limit 256Mi
- Limit file
- /sys/fs/cgroup/…/cri-containerd-9c2f7a….scope/memory.max
- Killer
- the kernel's OOM killer, scoped to the cgroup
- Exit code
- 137 = 128 + SIGKILL(9)
Read the whole lesson as text
1. Where the limit lives
The 256 Mi limit isn't a program or a watcher - it's a byte count in the container's cgroup, written by runc when the container started. Every page the kernel charges to this process increments a counter. When a charge would push the counter past memory.max, the kernel first tries to reclaim memory inside the cgroup; only when nothing is left to reclaim does it summon the OOM killer.
- The limit is one file in the container's cgroup, written at start and read by the kernel ever after.
2. Memory climbs
The app builds a monthly report. Its heap grows as pages stream in: 180 Mi at the halfway mark, 240 Mi a few seconds later. File cache counts too - reading the report's images charges the same cgroup, though the kernel will drop that cache first when the cgroup gets tight. At 255 Mi the app asks for one more page, and the charge crosses 268435456.
- Halfway through the report, 180 mebibytes are charged to the container.
- The heap keeps growing; the app has no idea a ceiling exists.
3. The kill
One more page, one charge too many. The kernel reclaims what it can, and the file cache goes, but the heap is anonymous memory with no swap to go to. So it runs its OOM killer - scoped: it picks the largest process inside the offending cgroup, not on the node. That's this container's app, and there's nothing else in the cgroup to choose. SIGKILL cannot be caught, blocked or ignored; the process vanishes mid-allocation with no chance to flush, log or say goodbye.
- The kernel kills the app instantly, mid-allocation.
4. Who reports it
containerd sees the exit - code 137, because 128 + 9 is how a signal death looks. It also watches the cgroup's memory.events, sees oom_kill go up, and labels the exit OOMKilled, so the kubelet knows this wasn't the app's choice. The Pod's status tells the story: lastState.terminated reason OOMKilled, exitCode 137. That word in kubectl get pods is a kernel counter, laundered into vocabulary.
- containerd reports exit 137 with reason OOMKilled, taken from the cgroup's oom_kill counter.
- The kubelet reports the container OOMKilled and starts the restart clock.
5. The loop and the fix
restartPolicy Always means the container returns in 10 seconds - and loads the same report. If the workload genuinely needs 300 Mi, every run ends OOMKilled, and between runs the Pod shows CrashLoopBackOff: the same backoff clock as any crash. The fix is one of two: raise the limit to fit the job, or fix the leak so the job fits the limit. Streaming the report instead of loading it drops the peak to 90 Mi - under the same 256.
- Ten seconds later the app restarts - and asks for the same report.
- The fix that fits the job: a bigger limit, rolled out like any change.
- The replacement Pod finishes the report and reports Ready.
Summary
The limit was one number in a cgroup file; the killer was the kernel, fenced to that cgroup; the report was a counter laundered into a reason string. No component of Kubernetes decided anything - which is the point: memory enforcement happens at allocation speed, below everything, and surfaces upward as the single word OOMKilled.
Next lesson: Mounting a volume