Troubleshooting with kubectl
The handful of commands that find out why a pod does not start or keeps restarting.
When something is wrong, work from the outside in: is the pod running, what does Kubernetes say about it and what does the application say?
The four commands
kubectl get pods
kubectl describe pod <name>
kubectl logs <name>
kubectl exec -it <name> -- shget podsshows the status and the number of restarts.describeshows events such as failed image pulls, failed scheduling or failed probes. Read the Events section at the bottom.logsshows what the application wrote. Add--previousto see the logs of the last crashed container.execopens a shell inside the container.
Common statuses
| Status | Usual cause |
|---|---|
| Pending | No node has enough CPU or memory, or the PVC is not bound |
| ImagePullBackOff | Wrong image name or tag, or no permission to the registry |
| CrashLoopBackOff | The application starts and exits. Read the logs |
| OOMKilled | The container used more memory than its limit |
Probes
A readiness probe tells Kubernetes when a pod can receive traffic. A liveness probe tells it when to restart the container. A badly tuned liveness probe can restart a healthy but slow application forever.
NoteUse kubectl get events --sort-by=.lastTimestamp to see what happened recently in the namespace.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.