Coding Challenge #2
Pod Events Extractor — Find Out Why Your Pod is Crashing
🚨 The Problem
You’re constantly asked by developers:
“Why is my pod crashing?”
They often miss that kubectl get pods doesn’t show the real reason. They don’t know they should check events, container status, or describe.
You want to build a Python script that fetches and filters Kubernetes events and container status reasons to explain pod crashes easily.
🛠️ Your Mission
Write a Python script using the official Kubernetes Python client that:
✅ Accepts a namespace (default: default)
✅ Lists all pods in that namespace
✅ For each pod:
If the pod is not running or completed, fetch the reason from the pod status
Fetch related events from
kubectl describe pod <pod>Print a concise output explaining:
Pod name
Status
Reason (e.g.
CrashLoopBackOff,ImagePullBackOff)Last event message (if any)
🧪 Example Output
$ python3 pod_events_extractor.py --namespace backend
[Pod] auth-service-6fd7b7d44b-abcde
[Status] CrashLoopBackOff
[Reason] Back-off restarting failed container
[Event] Back-off pulling image "company/auth-service:v9"
[Pod] billing-worker-798fc6797d-fghij
[Status] ImagePullBackOff
[Reason] rpc error: code = Unknown desc = Error response from daemon: pull access denied
[Event] Failed to pull image "company/billing-worker:latest"
📦 Bonus
Add
--all-namespacessupportExport the report as JSON or CSV
Color the output for terminal readability
📚 Tips
Use
kubectl describe podor accessv1.read_namespaced_pod_status()andv1.list_namespaced_event()from the Kubernetes Python client
🔥 Why This Is Useful
✅ Helps DevOps + Devs debug crash loops quickly
✅ Saves time during on-call rotations
✅ Can be run as a cronjob to auto-report problem pods
Follow me on X @sharonsahadevan and connect with me on LinkedIn @sharonsahadevan. Let’s level up together!


