| name | kubernetes-troubleshooting |
| description | Debug Kubernetes pods, services, networking, and scaling issues. Use this skill when troubleshooting K8s deployments, investigating pod failures, or diagnosing cluster problems. |
| alwaysApply | false |
Kubernetes Troubleshooting
You are a Kubernetes expert. Use these systematic debugging patterns when investigating K8s issues.
Diagnostic Decision Tree
Pod not running?
├── Pending → Resource constraints or scheduling issues
│ ├── kubectl describe pod <name> → check Events
│ ├── Insufficient CPU/memory → scale cluster or reduce requests
│ ├── Node selector/affinity not matching → check node labels
│ └── PVC not bound → check storage class and PV availability
├── CrashLoopBackOff → Application crashing on startup
│ ├── kubectl logs <pod> → check application logs
│ ├── kubectl logs <pod> --previous → check last crash logs
│ ├── OOMKilled → increase memory limits
│ ├── Exit code 1 → application error (bad config, missing env)
│ └── Exit code 137 → killed by OOM or liveness probe
├── ImagePullBackOff → Can't pull container image
│ ├── Image name typo → verify image:tag exists
│ ├── Private registry → check imagePullSecrets
│ └── Rate limited → Docker Hub pull limit, use mirror
├── Running but not Ready → Readiness probe failing
│ ├── Check readiness probe config
│ ├── Application not listening on expected port
│ └── Dependency not available (database, cache)
└── Evicted → Node pressure
├── Disk pressure → clean up images, expand disk
└── Memory pressure → reduce workload or add nodes
Essential Debug Commands
Pod Investigation
kubectl get pods -A
kubectl get pods -o wide
kubectl get pods --sort-by='.status.startTime'
kubectl describe pod <name>
kubectl logs <name>
kubectl logs <name> --previous
kubectl logs <name> -c <container>
kubectl logs <name> --tail=100 -f
kubectl exec -it <name> -- /bin/sh
kubectl exec -it <name> -- env
kubectl exec -it <name> -- cat /etc/resolv.conf
kubectl top pods
kubectl top nodes
Service & Networking
kubectl get endpoints <service>
kubectl get svc <service> -o yaml
kubectl exec -it <pod> -- nslookup <service>
kubectl exec -it <pod> -- wget -qO- http://<service>:<port>/health
kubectl run debug --image=nicolaka/netshoot -it --rm -- /bin/bash
kubectl get ingress -A
kubectl describe ingress <name>
Cluster Health
kubectl get nodes
kubectl describe node <name>
kubectl get events --sort-by='.lastTimestamp'
kubectl cluster-info
Common Issues and Fixes
CrashLoopBackOff
kubectl logs <pod> --previous
kubectl run debug --image=<same-image> --command -- sleep 3600
kubectl exec -it debug -- /bin/sh
OOMKilled (Exit Code 137)
kubectl describe pod <name> | grep -A 5 "Limits"
resources:
requests:
memory: "256Mi"
limits:
memory: "512Mi"
kubectl top pod <name>
Service Not Reachable
kubectl get pods -l app=<name>
kubectl get endpoints <service>
kubectl get svc <service> -o jsonpath='{.spec.ports[*]}'
kubectl get networkpolicy -A
Persistent Volume Issues
kubectl describe pvc <name>
kubectl get storageclass
kubectl get pv
Resource Right-Sizing
Requests vs Limits
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
Rules of thumb:
requests = average usage + 20% buffer
limits = peak usage + 30% buffer
- Never set
limits without requests
- CPU limits cause throttling — some teams only set requests for CPU
- Memory limits are hard — OOMKilled if exceeded
HPA (Horizontal Pod Autoscaler)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Quick Reference
| Symptom | First Command | Likely Cause |
|---|
| Pod pending | kubectl describe pod | Resource constraints |
| Pod crashing | kubectl logs --previous | App error or OOM |
| Service unreachable | kubectl get endpoints | Label mismatch or no ready pods |
| Slow response | kubectl top pods | CPU throttling or memory pressure |
| DNS not resolving | kubectl exec -- nslookup | CoreDNS issue or network policy |
| Storage error | kubectl describe pvc | No matching PV or storage class |