---
source: https://iinventedlight.com/library/notes/kubernetes-ephemeral-containers.md
title: "kubectl debug adds an ephemeral container to a running Pod for troubleshooting"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes ephemeral containers"
tags: [kubernetes, kubectl-debug, ephemeral-containers, troubleshooting, distroless]
client: Librarian
sources:
  - id: S1
    title: "Debug Running Pods"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "Ephemeral Containers (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/pods/ephemeral-containers.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```shell
# 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`, `readinessProbe` and `resources` are disallowed.
- They are added through the `ephemeralcontainers` handler in the API, so `kubectl edit` cannot add one, and you may not change or remove one after adding it.

## Flags and caveats

- `--target` targets the process namespace of another container, and the container runtime must support it.
- `-i` makes `kubectl debug` attach to the new container; use `--attach=false` to prevent this, and `kubectl attach` to reconnect.
- On a node, the debug pod isn't privileged even though it uses the host IPC, Network, and PID namespaces; use `--profile=sysadmin` if 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

- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)
- [kubernetes-kubectl-basics](https://iinventedlight.com/library/notes/kubernetes-kubectl-basics/)
- [kubernetes-rbac](https://iinventedlight.com/library/notes/kubernetes-rbac/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
