Stage 2, Part 3 of 9 · p. 12, kubectl Mastery & Debugging

PART 3: PRODUCTION FAILURE MODES

17. Top 10 Debugging Failures

#FailureSymptomRoot CauseFix
1Debugging in wrong context"Why isn't this working?"Current context ≠ intended clusterkubectl config current-context
2Debugging in wrong namespace"Pod not found"Wrong namespacekubectl config view --minify
3Events expiredNo events to inspectEvents last 1 hourUse event exporter
4Logs goneCan't find root causeContainer restarted, old logs goneUse --previous or log aggregation
5Distroless no-shellCan't execImage has no shellUse kubectl debug
6Metrics API downkubectl top failsmetrics-server not installedInstall metrics-server
7Version skewCommand fails oddlykubectl too old/newMatch kubectl version
8RBAC denied"forbidden" errorsInsufficient permissionskubectl auth can-i
9Wrong resource name"not found"Typo, wrong kindkubectl get <resource>
10Stale kubeconfigAuth failuresToken expired, cert expiredRe-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

SymptomFirst CommandThen
Pod not startingkubectl describe podkubectl logs --previous
Service unreachablekubectl get endpointskubectl describe svc
Node issueskubectl describe nodeSSH to node
Permission deniedkubectl auth can-iCheck RBAC
Slow performancekubectl topCheck limits
"Not found"kubectl config current-contextVerify namespace

19. Blast Radius Analysis

When kubectl Fails

ComponentImpactSeverity
kubectl unavailableCan't manage clusterSEV-2
kubeconfig lostCan't authenticateSEV-2
API server downkubectl unusable; Pods keep runningSEV-1
RBAC revokedSpecific user blockedSEV-2
Wrong contextActions in wrong clusterSEV-1 (potential)

Mitigation

StrategyImplementation
Backup kubeconfigSecure storage
Multiple kubeconfigsPer-cluster, per-role
kubectx/kubensAvoid wrong-context mistakes
Shell promptShow current context
RBAC auditingRegular kubectl auth can-i reports
Emergency accessBreak-glass kubeconfig

1:1 copy of the class Google Doc, code in code blocks.