| name | k8s-debug |
| description | Kubernetes debugging and troubleshooting workflows |
| homepage | https://kubernetes.io/docs/tasks/debug/ |
| metadata | {"emoji":"🔍","version":"1.0.0","author":"Gourav Shah","license":"MIT","requires":{"bins":["kubectl"]},"tags":["kubernetes","debugging","sre","troubleshooting"]} |
Kubernetes Debugging
Expert guidance for diagnosing and resolving Kubernetes issues.
When to Use This Skill
Use this skill when:
- Pods are not running or restarting
- Services are not responding
- Deployments are stuck
- Resource issues are suspected
- Network connectivity problems occur
Quick Diagnosis Commands
Check Pod Status
kubectl get pods -A | grep -v Running | grep -v Completed
kubectl get pods -n <namespace> -o wide
kubectl describe pod <pod-name> -n <namespace>
Check Events
kubectl get events -A --sort-by='.lastTimestamp' | tail -20
kubectl get events --field-selector involvedObject.name=<pod-name>
Check Logs
kubectl logs <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace> --previous
kubectl logs <pod-name> --timestamps
kubectl logs <pod-name> -f
kubectl logs <pod-name> -c <container-name>
Common Pod States and Solutions
CrashLoopBackOff
Symptoms: Pod repeatedly crashes and restarts.
Diagnosis:
kubectl logs <pod-name> --previous
kubectl describe pod <pod-name> | grep -A 10 Events
kubectl get pod <pod-name> -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
Common Causes:
- Application error - Check logs for stack traces
- Missing config/secrets - Verify ConfigMaps and Secrets exist
- Resource limits too low - Check if OOMKilled
- Liveness probe failing - Review probe configuration
- Missing dependencies - Database, external service not reachable
ImagePullBackOff
Symptoms: Container image cannot be pulled.
Diagnosis:
kubectl describe pod <pod-name> | grep -E "(Image|Events)" -A 5
Common Causes:
- Wrong image name/tag - Verify image exists in registry
- Private registry auth - Check imagePullSecrets
- Network issues - Registry not reachable
- Rate limiting - Docker Hub rate limits
Fix:
kubectl create secret docker-registry regcred \
--docker-server=<registry> \
--docker-username=<user> \
--docker-password=<password>
Pending
Symptoms: Pod stays in Pending state.
Diagnosis:
kubectl describe pod <pod-name> | grep -A 5 "Events"
kubectl describe nodes | grep -A 5 "Allocated resources"
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints
Common Causes:
- Insufficient resources - Not enough CPU/memory on nodes
- Node selector mismatch - No nodes match selector
- Taints/tolerations - Pod doesn't tolerate node taints
- PVC not bound - Persistent volume not available
OOMKilled
Symptoms: Container killed due to memory limit.
Diagnosis:
kubectl get pod <pod-name> -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}'
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].resources}'
Fix:
- Increase memory limits in deployment
- Optimize application memory usage
- Add memory monitoring
Resource Debugging
Check Resource Usage
kubectl top nodes
kubectl top pods -A --sort-by=memory
kubectl top pods -n <namespace>
Check Resource Requests/Limits
kubectl get pods -A -o custom-columns=\
'NAMESPACE:.metadata.namespace,NAME:.metadata.name,CPU_REQ:.spec.containers[*].resources.requests.cpu,MEM_REQ:.spec.containers[*].resources.requests.memory,CPU_LIM:.spec.containers[*].resources.limits.cpu,MEM_LIM:.spec.containers[*].resources.limits.memory'
Network Debugging
Check Service Connectivity
kubectl get endpoints <service-name>
kubectl get pods -l <service-selector>
kubectl run debug --rm -it --image=busybox -- wget -qO- http://<service>:<port>
DNS Issues
kubectl run debug --rm -it --image=busybox -- nslookup <service-name>
kubectl get pods -n kube-system -l k8s-app=kube-dns
Quick Fixes
Restart Deployment
kubectl rollout restart deployment/<name> -n <namespace>
kubectl rollout status deployment/<name> -n <namespace>
Scale Deployment
kubectl scale deployment/<name> --replicas=3 -n <namespace>
Delete Stuck Pod
kubectl delete pod <pod-name> --grace-period=0 --force
Debugging Checklist
- Check pod status:
kubectl get pods
- Check events:
kubectl get events --sort-by='.lastTimestamp'
- Check logs:
kubectl logs <pod>
- Check describe:
kubectl describe pod <pod>
- Check resources:
kubectl top pods
- Check network: Test service connectivity
- Check config: Verify ConfigMaps/Secrets
Related Skills
- k8s-deploy: For deployment issues
- log-analysis: For log pattern analysis
- incident-response: For structured incident handling