Dev Overflow Logo

Dev Overflow

Global search

Search across questions, answers, users and tags.

Loading...
save

Kubernetes pod keeps restarting with OOMKilled — how do I find the cause?

clock icon

asked 1 month ago

message icon

2

eye icon

698

A Node service restarts every few hours. kubectl describe pod shows:

1Last State: Terminated
2 Reason: OOMKilled
3 Exit Code: 137
1Last State: Terminated
2 Reason: OOMKilled
3 Exit Code: 137

The memory limit is 512Mi. Do I just raise it, or is that hiding a real leak?

2 Answers

Find out which before you touch the limit. Plot container_memory_working_set_bytes over a few restart cycles:

  • Sawtooth that plateaus below the limit, then gets killed on a spike → the limit is genuinely too low.
  • Steady climb that never plateaus → a leak; raising the limit only lengthens the interval between restarts.

For Node specifically, also set the heap ceiling below the container limit:

1env:
2 - name: NODE_OPTIONS
3 value: "--max-old-space-size=384"
1env:
2 - name: NODE_OPTIONS
3 value: "--max-old-space-size=384"

Otherwise V8 happily grows past 512Mi and the kernel kills the process before the garbage collector ever feels pressure.

Worth checking requests too, not just limits. If requests are far below actual usage the scheduler overpacks the node, and you get evictions that look like OOM kills but are really node memory pressure.

1

of 1

Write your answer here

Introduce the problem and expand on what you've put in the title.

Top Questions