Ephemeral Containers — debug containers injected into running Pods.
1# Add debug container to running Pod2kubectl debug -it my-pod --image=busybox:1.36 --target=app34# Debug with custom profile5kubectl debug -it my-pod \6 --image=nicolaka/netshoot \7 --target=app \8 -- /bin/bash910# Debug node (use ephemeral container on node)11kubectl 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 from ephemeral container25kubectl cp my-pod:/app/logs/error.log ./error.log -c debugger2627# Remove ephemeral container (not supported - Pod must be recreated)
1# Pod with ephemeral container in spec2apiVersion: 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: ""
Use cases: