← All one-liners·#056·Kubernetes·self contained·power

Find all OOMKilled pods across a Kubernetes cluster

Scan all namespaces to identify pods that recently crashed due to Out Of Memory (OOMKilled) errors.

Setup
  • → kubectl installed and configured with cluster access
  • → jq installed
Cost per run
Free
The one-liner
$ kubectl get pods -A -o json | jq -r '.items[] | select(.status.containerStatuses[]?.lastState.terminated.reason == "OOMKilled") | "\(.metadata.namespace)/\(.metadata.name)"'
What each stage does
  1. [01] kubectlkubectl get pods -A -o json
    Fetches all pods across all namespaces and outputs the raw data in JSON format.
  2. [02] jqjq -r '.items[]'
    Iterates over the array of pod objects and outputs raw strings instead of quoted JSON.
  3. [03] jqselect(.status.containerStatuses[]?.lastState.terminated.reason == "OOMKilled")
    Filters the pods to only those where at least one container's last termination reason was an Out Of Memory kill.
  4. [04] jq"\(.metadata.namespace)/\(.metadata.name)"
    Formats the output to show the namespace and pod name separated by a slash.
Expected output (sample)
kube-system/metrics-server-5f8f5678-abcde
default/data-processor-worker-1
monitoring/prometheus-adapter-7b5f9c9d-xyz
production/redis-cache-0
Caveats & tips
  • Requires cluster-wide RBAC permissions to list pods in all namespaces.
  • Only checks the lastState of containers; it won't catch pods that have OOMKilled multiple times and restarted for other reasons since.