kubernetes kubectl ·

Debug Kubernetes CrashLoopBackOff in 30 Seconds

Quick command to instantly find why your pod is crash-looping.

Advertisement

The Problem

Your pod is stuck in CrashLoopBackOff and you need to find out why — fast.

The Solution

kubectl logs <pod-name> --previous

The --previous flag shows logs from the last crashed container instance. This is the single most useful flag for debugging crash loops.

Combine with describe for the full picture

kubectl describe pod <pod-name> | grep -A 5 "Last State"

This shows the exit code and reason for the last termination:

Last State:  Terminated
  Reason:    OOMKilled
  Exit Code: 137

Common Exit Codes

CodeMeaningFix
1Application errorCheck app logs
137OOMKilledIncrease memory limits
139SegfaultCheck binary compatibility
143SIGTERMGraceful shutdown issue

Why It Works

Kubernetes keeps logs from the previous container instance even after it crashes. Without --previous, you’d only see logs from the current (possibly empty) instance that hasn’t had time to produce output before crashing again.

Advertisement

Stay up to date

Get DevOps tips, tutorials, and guides delivered to your inbox.