PART 7: INCIDENT MANAGEMENT
35. kubectl Incident Post-Mortem Template
text
INCIDENT: Production Outage - Wrong Context Used During Debugging
DATE: 2024-01-15
DURATION: 23 minutes
SEVERITY: SEV-1
IMPACT: A debug command accidentally ran against production instead of staging.
TIMELINE:
14:00 - Engineer debugging staging issue
14:05 - Ran kubectl delete pod --all -n staging
14:06 - Realized wrong context was active
14:07 - Verified prod pods deleted
14:08 - Initiated incident response
14:15 - Rolled forward: restarted all deleted Pods via Deployments
14:20 - All services restored
14:23 - Incident closed
ROOT CAUSE:
Engineer had two terminals open. One had prod context, the other had
staging. The destructive command ran against the wrong terminal.
LESSONS LEARNED:
1. Context visibility in shell prompt is critical.
2. Destructive commands need confirmation prompts.
3. kubectx/kubens should be standard.
ACTION ITEMS:
[ ] Enforce context in shell prompt across the org (Owner: Platform, Due: 2024-01-18)
[ ] Add confirmation prompts for destructive commands (Owner: Platform, Due: 2024-01-20)
[ ] Training on context management (Owner: Team Lead, Due: 2024-01-25)
36. On-Call Runbook: kubectl Debugging
text
SYMPTOM: Alert fired; need to debug via kubectl.
STEP 1: Verify context and namespace
$ kubectl config current-context
$ kubectl config view --minify | grep namespace
STEP 2: High-level health check
$ kubectl get nodes
$ kubectl get pods -A | grep -v "Running\|Completed"
$ kubectl get events -A --field-selector type=Warning | tail -20
STEP 3: Focus on the affected service
$ kubectl get pods -l app=<service> -o wide
$ kubectl describe pod <specific-pod>
$ kubectl logs <specific-pod> --tail=100
STEP 4: Check connectivity
$ kubectl get endpoints <service>
$ kubectl get svc <service> -o yaml
STEP 5: Check resources
$ kubectl top pods -l app=<service>
$ kubectl describe node <node>
STEP 6: If Pod is broken
$ kubectl logs <pod> --previous
$ kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[0].lastState}'
STEP 7: If deeper debugging needed
$ kubectl debug -it <pod> --image=nicolaka/netshoot --target=<container>
STEP 8: Document and escalate
37. Escalation Matrix
| Severity | Impact | Response Time | Escalation |
| SEV-1 | Cluster-wide outage | 5 min | On-call + Platform + Management |
| SEV-2 | Service outage / degraded | 15 min | On-call + Platform |
| SEV-3 | Single Pod issue | 1 hour | On-call |
| SEV-4 | Configuration issue | 4 hours | Ticket |
1:1 copy of the class Google Doc, code in code blocks.