Stage 2, Part 3 of 9, kubectl Mastery & Debugging
Text
PART 3: PRODUCTION FAILURE MODES
17. Top 10 Debugging Failures
| # | Failure | Symptom | Root Cause | Fix |
| 1 | Debugging in wrong context | "Why isn't this working?" | Current context ≠ intended cluster | kubectl config current-context |
| 2 | Debugging in wrong namespace | "Pod not found" | Wrong namespace | kubectl config view --minify |
| 3 | Events expired | No events to inspect | Events last 1 hour | Use event exporter |
| 4 | Logs gone | Can't find root cause | Container restarted, old logs gone | Use --previous or log aggregation |
| 5 | Distroless no-shell | Can't exec | Image has no shell | Use kubectl debug |
| 6 | Metrics API down | kubectl top fails | metrics-server not installed | Install metrics-server |
| 7 | Version skew | Command fails oddly | kubectl too old/new | Match kubectl version |
| 8 | RBAC denied | "forbidden" errors | Insufficient permissions | kubectl auth can-i |
| 9 | Wrong resource name | "not found" | Typo, wrong kind | kubectl get <resource> |
| 10 | Stale kubeconfig | Auth failures | Token expired, cert expired | Re-auth, refresh kubeconfig |
18. Kubernetes Debugging Runbook
"Something is Broken" — Step-by-Step
text
STEP 1: Verify context and namespace
$ kubectl config current-context
$ kubectl config view --minify | grep namespace
STEP 2: Get the high-level picture
$ kubectl get pods -A | grep -v Running
$ kubectl get events -A --sort-by=.metadata.creationTimestamp | tail -20
$ kubectl get nodes
$ kubectl cluster-info
STEP 3: Identify the broken resource
$ kubectl describe pod <pod>
# Read Events at the bottom
STEP 4: Get logs
$ kubectl logs <pod> --tail=100
$ kubectl logs <pod> --previous
$ kubectl logs -l <label> --tail=50
STEP 5: Check endpoints and service
$ kubectl get svc <svc>
$ kubectl get endpoints <svc>
$ kubectl describe svc <svc>
STEP 6: Check resource usage
$ kubectl top pod <pod>
$ kubectl top node
STEP 7: Check nodes
$ kubectl describe node <node>
$ kubectl get --raw /api/v1/nodes/<node>/proxy/stats/summary | jq
STEP 8: For deeper debugging
$ kubectl debug -it <pod> --image=busybox --target=<container>
STEP 9: Check permissions (if "forbidden")
$ kubectl auth can-i <verb> <resource> -n <namespace>
STEP 10: Check config
$ kubectl get configmap <name> -o yaml
$ kubectl get secret <name> -o yaml
STEP 11: Escalate if unresolved
Quick Diagnostic Table
| Symptom | First Command | Then |
| Pod not starting | kubectl describe pod | kubectl logs --previous |
| Service unreachable | kubectl get endpoints | kubectl describe svc |
| Node issues | kubectl describe node | SSH to node |
| Permission denied | kubectl auth can-i | Check RBAC |
| Slow performance | kubectl top | Check limits |
| "Not found" | kubectl config current-context | Verify namespace |
19. Blast Radius Analysis
When kubectl Fails
| Component | Impact | Severity |
| kubectl unavailable | Can't manage cluster | SEV-2 |
| kubeconfig lost | Can't authenticate | SEV-2 |
| API server down | kubectl unusable; Pods keep running | SEV-1 |
| RBAC revoked | Specific user blocked | SEV-2 |
| Wrong context | Actions in wrong cluster | SEV-1 (potential) |
Mitigation
| Strategy | Implementation |
| Backup kubeconfig | Secure storage |
| Multiple kubeconfigs | Per-cluster, per-role |
| kubectx/kubens | Avoid wrong-context mistakes |
| Shell prompt | Show current context |
| RBAC auditing | Regular kubectl auth can-i reports |
| Emergency access | Break-glass kubeconfig |
1:1 copy of the class Google Doc, code in code blocks.