Ephemeral Containers — inject debug containers into running Pods.
1# Add debug container2kubectl debug -it my-pod --image=busybox:1.36 --target=app34# Debug with specific profile5kubectl debug -it my-pod \6 --image=nicolaka/netshoot \7 --target=app \8 -- /bin/bash910# Debug node11kubectl debug node/node-1 -it --image=busybox:1.361213# Add ephemeral container via patch14kubectl patch pod my-pod -p '{"spec":{"ephemeralContainers":[{15 "name":"debugger",16 "image":"busybox:1.36",17 "stdin":true,18 "tty":true19}]}}'2021# Attach to ephemeral container22kubectl attach -it my-pod -c debugger2324# Copy files from ephemeral container25kubectl cp my-pod:/app/logs/error.log ./error.log -c debugger2627# View ephemeral container logs28kubectl logs my-pod -c debugger
1# Pod with ephemeral container2apiVersion: v13kind: Pod4metadata:5 name: my-pod6spec:7 containers:8 - name: app9 image: myapp:latest10 ephemeralContainers:11 - name: debugger12 image: busybox:1.3613 stdin: true14 tty: true15 targetNamespace: ""
Debug Tools:
Use cases: