Ephemeral Containers in Kubernetes is a powerful way to debug running Pods without modifying their original spec or restarting them
🔧 What Are Ephemeral Containers?
- Purpose: Temporary containers added to a running Pod for debugging.
- Not part of the Pod spec: You can’t define them in a YAML file like regular containers.
- No restart: They don’t restart on failure and don’t affect the Pod lifecycle.
- Requires Kubernetes 1.23+ and
EphemeralContainersfeature gate enabled.
🧪 Prerequisites
- Kubernetes cluster version 1.23 or higher.
kubectlCLI installed.- Ephemeral containers feature enabled in your cluster.
🚀 How to Use Ephemeral Containers
✅ Step-by-Step Example
Let’s say you have a Pod named my-app-pod and you want to debug it using a busybox container.
1. Check the Pod
kubectl get pod my-app-pod
2. Add an Ephemeral Container
Use kubectl debug to inject the container:
kubectl debug -it my-app-pod –image=busybox –target=my-app-container
-it: Interactive terminal.--image: The image to use for the ephemeral container.--target: The container you want to debug (optional).
This opens a shell inside the ephemeral container.
3. Run Debug Commands
Once inside, you can run commands like:
ps aux
netstat -tuln
cat /etc/config.yaml
4. Exit When Done
Just type exit to leave the ephemeral container. It will remain in the Pod until the Pod is deleted or restarted.
View Ephemeral Containers
To see ephemeral containers added to a Pod:
kubectl get pod my-app-pod -o jsonpath='{.spec.ephemeralContainers}’
Leave a Reply