⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 10 of 207 in Kubernetes
Senior DevOps / SRE Kubernetes Observability & CLI Tooling Core Diagnostics
🎯 Target Role / Context: Production Kubernetes Administration

Q: How do you check Kubernetes pod logs and events?

Practical command toolkit for inspecting Kubernetes pod logs and cluster events: previous container crashes, multi-container pods, real-time log streaming with Stern, and filtering events with JSONPath.

#Kubernetes #kubectl logs #kubectl events #Debugging #Stern #CLI
🎙️ Candidate Opening & Architectural Context
"Checking logs and events is fundamental, but in large-scale production with multi-container pods, crashing containers, and thousands of events, using standard 'kubectl logs' alone is insufficient."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: Checking logs and events is fundamental, but in large-scale production with multi-container pods, crashing containers, and thousands of events, using standard 'kubectl logs' alone is insufficient.

1️⃣

Mastering Pod Logs (Crashing, Multi-Container, Live Stream)

Essential commands for container log inspection:

  • kubectl logs <pod-name> -f: Real-time stream (follow) of container stdout/stderr.
  • kubectl logs <pod-name> --previous: The crashed container command — inspects logs of the container instance that just crashed before restarting.
  • kubectl logs <pod-name> -c <container-name>: Explicitly targets a container in multi-container pods (e.g. Istio sidecar vs app container).
  • kubectl logs deployment/<app> --all-containers=true --tail=50: Triage all pods in a deployment simultaneously.
  • stern <app-prefix> -n prod --since 15m: Cross-pod color-coded log aggregator that tails all pods matching a regex even as pods restart.
2️⃣

Mastering Cluster Events (Sorting, Filtering & Warning Triage)

Events explain WHY pods are failing, evicted, or unschedulable:

  • kubectl get events -n <ns> --sort-by='.metadata.creationTimestamp': Chronological event timeline of recent cluster occurrences.
  • kubectl get events --field-selector type=Warning -n <ns>: Filters noise to show only warnings (FailedScheduling, Unhealthy, FailedMount, BackOff).
  • kubectl events -n <ns>: Modern K8s 1.23+ dedicated command with clean human-readable table formatting.
  • kubectl get events --field-selector involvedObject.name=<pod-name>: Filters events tied strictly to a specific pod.
Advertisement
3️⃣

Deep Debugging: Ephemeral Containers & Node Logs

When container logs are silent or container won't run:

  • kubectl debug -it <pod-name> --image=nicolaka/netshoot --target=<app>: Attaches an ephemeral container with tcpdump, curl, and dig sharing the pod's network and process namespace.
  • Node kubelet logs: If the node itself is unresponsive: journalctl -u kubelet -e on the host.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Always use '--previous' to catch the smoking gun of a crashed container. Filter events by 'type=Warning' to eliminate noise, and leverage 'stern' for multi-pod regex log streaming across autoscaling pods."
⚡ 60-Second Elevator Pitch Talking Points
  • Current logs: 'kubectl logs <pod> -f' (add -c for specific container).
  • Crashed logs: 'kubectl logs <pod> --previous' to see crash stack trace.
  • Multi-pod streaming: Use 'stern <app-pattern>' for live tailing across all replicas.
  • Events: 'kubectl get events -n <ns> --sort-by=.metadata.creationTimestamp' and filter by 'type=Warning'.
  • Zero-downtime debugging: 'kubectl debug' to attach ephemeral netshoot container with diagnostics tools.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Over-granting cluster-admin permissions to pod ServiceAccounts instead of scoping namespace Roles when configuring Kubernetes Logs Events Over-granting cluster-wide permissions violates least-privilege principles and allows compromised pods to escalate privileges across namespaces.
  2. Referencing mutable latest container tags across production Kubernetes Deployment specs when configuring Kubernetes Logs Events Deployments referencing :latest risk inconsistent versions across replica pods and break deterministic rollback capabilities.
  3. Omitting pod readiness probes, causing traffic to hit uninitialized application containers when configuring Kubernetes Logs Events Readiness probes gate traffic delivery; missing probes cause Kubernetes to route user requests to pods before dependencies or caches are loaded.
  4. Executing diagnostic triage without analyzing chronological cluster events and describe outputs when configuring Kubernetes Logs Events Cluster events provide sequential timestamps of scheduler decisions, probe failures, and image pull timeouts essential for rapid root-cause isolation.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →