l2t

Kubernetes: How to debug a pod?

Asked: 3 months ago

The first step in debugging a Pod is taking a look at it and check the status of each container.

kubectl describe pods <pod-name>

My pod stays pending

If a Pod is stuck in Pending it means that it can not be scheduled onto a node. Have a look at the reason column. There may be two reasons

  • You don’t have enough resources
    • Your resources like CPU or Memory may be exhausted
    • Try changing resource request and delete and re-create pod
  • You are using hostPort
    • hostPort is unnecessary, try using a Service object to expose your Pod
    • If you do require hostPort then you can only schedule as many Pods as there are nodes

My pod stays waiting

If a Pod is stuck in the Waiting state, then it has been scheduled to a worker node, but it can’t run on that machine. The most common cause of Waiting pods is a failure to pull the image.

  • Make sure that you have the name of the image correct.
  • Have you pushed the image to the repository?
  • Run a manual docker pull image on your machine to see if the image can be pulled

My pod is crashing or unhealthy

# check the current logs
kubectl logs <pod-name> <container-name>

# if failed previously
kubectl logs --previous <pod-name> <container-name>

# check the logs in a container
kubectl exec <pod-name> -c <container-name> -- <cmd> <args...>
Viewed: 103 times
Liked: 4 times