Sub topic 7
Debugging a node
Some failures sit below the pod. Examples are a full disk, a kubelet that logs errors, or a container runtime that won't start containers. This chapter covers kubectl debug node/NAME, which gives you a shell on the node without SSH access. It assumes you know how to run kubectl debug against a pod and understand the basics of RBAC and Linux filesystems.
When to debug the node
Look at the node when pod-level checks don't explain the symptom. Typical signals:
- Several pods on one node fail while the same workloads run fine elsewhere.
kubectl describe nodeshows conditions such asDiskPressure,MemoryPressure, orNotReady.- Pods stay in
ContainerCreatingand the events mention the runtime or the network plugin. - You need kubelet or container runtime logs, and you have no SSH route to the machine.
How node debugging works
kubectl debug node/NAME does not attach to the node itself. It creates a new pod, scheduled on that node, and attaches your terminal to it. The pod runs with the node's host namespaces for IPC, network, and PID. The node's root filesystem is mounted inside the pod at /host.
kubectl debug node/worker-1 -it --image=busybox:1.36
# inside the debug pod, the node's root filesystem is mounted at /host
ls /host/var/logThe command prints the generated pod name, which looks like node-debugger-worker-1-xxxxx. You need that name for cleanup later.
What you can inspect
Your shell runs in the container's own root filesystem, so the node's files are under /host. A path such as /var/log/syslog on the node is /host/var/log/syslog in the debug pod.
Useful places to look:
/host/var/log/for system logs and, on many distributions,/host/var/log/pods/and/host/var/log/containers/for container logs./host/etc/kubernetes/for kubelet configuration and static pod manifests, depending on how the cluster was built./host/var/lib/kubelet/for pod volumes and kubelet state.
Because the pod shares the host network namespace, tools such as ip addr and netstat show the node's own interfaces and sockets. Use an image that ships those tools. busybox has basic versions of them.
If you need the node's own binaries, run chroot /host to make the node's filesystem your root. This only works if the debug image includes chroot and the node has a shell, and it gives you the node's tools such as journalctl where they exist.
chroot /host
journalctl -u kubelet --no-pager | tail -n 50Many managed node images are minimal and may not offer a shell or journalctl. In that case read the log files directly through /host/var/log.
Privileges and profiles
The default node profile gives the debug pod access to host namespaces and the host filesystem. It does not make the container fully privileged. For tasks that need more, such as changing kernel settings or running strace on host processes, choose a profile with --profile. The sysadmin profile grants broad privileges and is the most powerful setting. Use the least privileged profile that lets you finish the task.
kubectl debug node/worker-1 -it --image=busybox:1.36 --profile=sysadminCleanup
The debug pod is not removed when you exit the shell. It stays in the namespace, usually default unless you pass -n, and it ends up in Completed or Error state. Delete it when you are done:
kubectl get pods
kubectl delete pod node-debugger-worker-1-xxxxxNewer kubectl versions offer --attach=false-style workflows and cleanup flags, but check kubectl debug --help for what your version supports before you rely on them.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `pods "node-debugger-..." is forbidden` | Your role cannot create pods in that namespace | Ask for pod create permission, or use a namespace where you have it |
| Debug pod stays `Pending` | The node is cordoned with taints the pod does not tolerate, or it has no free resources | Check `kubectl describe pod` events, and try a different namespace or profile |
| `chroot: can't execute '/bin/sh'` | The node image has no shell | Skip `chroot` and read files under `/host` directly |
| Pod admission rejects it | Pod Security settings block host namespaces or host paths | Use a namespace with a policy that allows it, such as one set to `privileged` |
Exercise
You run kubectl debug node/worker-1 -it --image=busybox:1.36 and want to read the kubelet's log files on the node. Where do you look, and what must you do afterward?
Show answer
The node's root filesystem is mounted at /host, so look under /host/var/log (for example /host/var/log/pods or /host/var/log/containers). The command does not delete the debug pod when you exit, so find its name with kubectl get pods and remove it with kubectl delete pod NAME.
Exercise
Why is node debugging considered administrator-level access, and which flag lets you pick how privileged the debug container is?
Show answer
The debug pod can read the node's whole filesystem, which includes data from every pod on that node, such as Secrets and tokens. The --profile flag selects the privilege level, and you should choose the least privileged profile that works.