kubectl debug adds an ephemeral container to a running Pod for troubleshooting
Answer: Run kubectl debug -it <pod> --image=busybox:1.28 --target=<container> to add an ephemeral container to the Pod and attach to it. Use them for interactive troubleshooting when a container has crashed or a container image doesn't include debugging utilities, so kubectl exec is insufficient.
Commands
# Add a debug container that shares the target's process namespace
kubectl debug -it ephemeral-demo --image=busybox:1.28 --target=ephemeral-demo
# Debug a copy of the Pod instead, with shared processes
kubectl debug myapp -it --image=ubuntu --share-processes --copy-to=myapp-debug
# Shell on a node (root filesystem at /host)
kubectl debug node/mynode -it --image=ubuntu
How they differ from regular containers
- Pods are intended to be disposable and replaceable, so once a Pod has been created you cannot add a regular container to it.
- They lack guarantees for resources or execution and will never be automatically restarted, so they are not appropriate for building applications.
- Fields such as
ports,livenessProbe,readinessProbeandresourcesare disallowed. - They are added through the
ephemeralcontainershandler in the API, sokubectl editcannot add one, and you may not change or remove one after adding it.
Flags and caveats
--targettargets the process namespace of another container, and the container runtime must support it.-imakeskubectl debugattach to the new container; use--attach=falseto prevent this, andkubectl attachto reconnect.- On a node, the debug pod isn't privileged even though it uses the host IPC, Network, and PID namespaces; use
--profile=sysadminif you need a privileged pod.
Permissions
The pods/ephemeralcontainers subresource is not included in the default admin and edit ClusterRoles. Cluster administrators must grant the patch (and typically update) verb on it explicitly.
See also
Claims
- id: C1 claim: Ephemeral containers are never automatically restarted. source: S2 evidence: "they will never be automatically restarted"
- id: C2 claim: kubectl edit cannot add an ephemeral container. source: S2 evidence: "it's not possible to add an ephemeral container using
kubectl edit"
- id: C3 claim: --target targets the process namespace of another container. source: S1 evidence: "The --target parameter targets the process namespace of another container."
Sources
- [S1] Debug Running Pods. Kubernetes docs. https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] Ephemeral Containers (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/pods/ephemeral-containers.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Debug Running Pods; kubernetes/website (GitHub), Ephemeral Containers (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Debug Running Pods; kubernetes/website (GitHub), Ephemeral Containers (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "kubectl debug adds an ephemeral container to a running Pod for troubleshooting." iinventedlight Library, iil:note:pnrhybz1, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-ephemeral-containers/. License: CC-BY-4.0.
@misc{iil_note_pnrhybz1,
author = {{iinventedlight}},
title = {{kubectl debug adds an ephemeral container to a running Pod for troubleshooting}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-ephemeral-containers/},
note = {Permanent ID iil:note:pnrhybz1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-ephemeral-containers.md.