Kubernetes Debugging
5 min read Quiz at the end
Debug pods with kubectl describe, logs, exec, debug ephemeral containers, and port-forward.
Debugging in Kubernetes
# Check pod status
kubectl get pods
kubectl describe pod mypod # events show errors
kubectl logs mypod
kubectl logs mypod -c sidecar # specific container
kubectl logs mypod --previous # crashed pod logs
# Shell into pod
kubectl exec -it mypod -- bash
kubectl exec -it mypod -c mycontainer -- sh
# Debug with ephemeral container
kubectl debug -it mypod --image=busybox --target=myapp
# Port forward to local machine
kubectl port-forward pod/mypod 8080:3000
kubectl port-forward svc/myapp-svc 8080:80
# Network debugging
kubectl run netdebug --image=nicolaka/netshoot -it --rm -- bash