Debugging Kubernetes Pods
4 min readSep 19, 2022
I have spent a lot of time with botched Kubernetes deployments, and I thought it might be worth sharing some of the things I’ve come across, typically when a helm install
hits a wall or a kubectl apply
goes awry.
All the variables below like $NAMESPACE
are things you should replace with values corresponding to what you’re trying to debug.
My tl;dr list is
# Set the current namespace
kubectl config set-context --current --namespace $NAMESPACE# Describe pod state
kubectl describe pod $POD_NAME# Pod logs, following output
kubectl logs -f $POD_NAME## Pod logs optionally with container name if necessary
kubectl logs $POD_NAME -c $CONTAINER_NAME## Pod logs on the previous container
kubectl logs -p $POD_NAME# Port forwarding## Either the service
kubectl port-forward svc/$SERVICE_NAME $LOCAL_PORT:$SERVICE_PORT
## or the pod itself
kubectl port-forward $POD_NAME $LOCAL_PORT:$POD_PORT