Room 36
KUBECTL DEBUG
The Diagnostic Lab
kubectl debuglets you attach ephemeral debug containers or create pod copies for troubleshooting.- A distroless pod has no shell - debug it with an ephemeral container.
📜 Mission Briefing
- Apply
distroless-pod.yaml- runs a Go binary in a distroless image (no shell). - Try
kubectl exec- it will fail (no/bin/sh). - Use
kubectl debugto attach a debug container: - From the debug container, read
/proc/1/environto find the password. - The password is
debugpod.
Key Commands
| Command | Purpose |
|---|---|
kubectl debug POD -it --image=IMG |
Attach ephemeral container |
kubectl debug POD -it --image=IMG --target=CONTAINER |
Share PID namespace |
kubectl debug POD --copy-to=NEW-POD --image=IMG |
Debug copy |
kubectl debug node/NODE -it --image=IMG |
Debug node |
kubectl debug
# Ephemeral debug container (shares pod namespaces)
kubectl debug my-pod -it --image=busybox --target=main
# --target=main: share PID namespace with container "main"
# Inside debug container: can see processes of "main"
# Debug copy (create a copy of the pod with modifications)
kubectl debug my-pod --copy-to=debug-pod --image=busybox -it
kubectl debug my-pod --copy-to=debug-pod --set-image=main=ubuntu -it
# Node debugging (creates a privileged pod on the node)
kubectl debug node/worker-1 -it --image=busybox
# Access host filesystem at /host
# chroot /host # get a host shell
# Ephemeral containers:
# - Added to running pods without restart
# - Share namespaces with the pod
# - Cannot be removed (pod must be deleted)
# - No ports, resources, or probes
# - Great for distroless images
Hints
Hint 2
Hint 3
The password is debugpod.