Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

Find which pods were OOMKilled in a namespace, with their container names and restart counts.

IntermediateScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → The last termination reason is in each container's status.

What I'd do →

kubectl get pods -n prod -o json | jq -r '
  .items[] | .metadata.name as $pod
  | .status.containerStatuses[]?
  | select(.lastState.terminated.reason == "OOMKilled")
  | [$pod, .name, .restartCount, .lastState.terminated.finishedAt] | @tsv' | column -t
  1. as $pod keeps the pod name while iterating containers.
  2. []? skips pods without container statuses (pending).
  3. Compare with limits: kubectl get pod POD -o jsonpath='{.spec.containers[*].resources.limits.memory}'.

Why → OOM kills hide behind generic CrashLoopBackOff; this lists them directly.

Interview tip → Mention that kubectl get events --field-selector reason=OOMKilling shows node-level OOMs, which are different from container limit kills.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions