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
as $podkeeps the pod name while iterating containers.[]?skips pods without container statuses (pending).- 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.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?IntermediateA vendor needs application logs, but they contain emails and card numbers. Mask them first.Intermediate