appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Troubleshooting with kubectl

Lesson 5 of 510 minIntermediate

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> -- sh
  • get pods shows the status and the number of restarts.
  • describe shows events such as failed image pulls, failed scheduling or failed probes. Read the Events section at the bottom.
  • logs shows what the application wrote. Add --previous to see the logs of the last crashed container.
  • exec opens a shell inside the container.

Common statuses

StatusUsual cause
PendingNo node has enough CPU or memory, or the PVC is not bound
ImagePullBackOffWrong image name or tag, or no permission to the registry
CrashLoopBackOffThe application starts and exits. Read the logs
OOMKilledThe 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.

1. A pod shows CrashLoopBackOff. What should you read first?
2. What does ImagePullBackOff usually mean?
Hintkubectl logs followed by the pod name.

Key terms