1 min read

Debug a running pod in Kubernetes


Debug toolkit

Stream logs from a pod:

logs.sh
kubectl logs -f my-pod --tail=100

Logs from a previous crashed container:

logs_prev.sh
kubectl logs my-pod --previous

Exec into a running container:

exec.sh
kubectl exec -it my-pod -- /bin/sh

Attach a debug container to a running pod (K8s 1.25+):

debug.sh
kubectl debug -it my-pod --image=busybox --target=my-container

Get events for a specific pod:

events.sh
kubectl get events --field-selector involvedObject.name=my-pod --sort-by=.lastTimestamp