How kubectl debug and ephemeral containers help teams debug distroless pods
When a pod crashes or its container image ships with no shell, the usual kubectl exec route fails, and the team needs a way to look inside without rebuilding the image. kubectl debug offers three paths: attach an ephemeral debug container to the running pod, copy the pod with a different image or command, or start a debugging pod on a node. Each path answers a different question, so the first decision is which one fits the failure. An ephemeral container suits a running pod whose state you need to inspect in place, a copied pod suits a crash loop you need to reproduce with a tools image and changed entrypoint, and a node debugging session suits problems that live in the host rather than the workload.
Ephemeral containers share the pod's network namespace and, depending on settings, process namespace, so a debug container can see the same sockets and files the application uses. That is what makes them useful for distroless images. The trade-off is permanence: an ephemeral container cannot be removed from the pod spec once added, and it stays until the pod is deleted. Confirm the cluster version supports the feature in your environment, and check the Kubernetes documentation only for authentication context, since the debug feature itself is documented separately in the upstream Kubernetes docs you will rely on during the build.
Before enabling any of this, decide who may create ephemeral containers and node debug pods. Attaching a debug container is effectively privileged access to the workload, and a node debugging pod can reach host resources, so both need explicit RBAC grants on the pods/ephemeralcontainers subresource and on pod creation in designated namespaces, rather than broad cluster-admin use. Check the Pod Security Standards level of the namespaces where debugging happens, because a debug container that requests elevated capabilities can conflict with a Restricted enforcement. Agree these rules with your security team in writing before the first incident, so the on-call engineer is not inventing the access model during an outage.
Choosing between ephemeral containers, pod copies and node debugging
Attaching an ephemeral container adds a temporary container to a pod that is already running, using kubectl debug with the pod name and a debug image. The new container shares some namespaces with the target container, so it can usually inspect the process list and network stack of the workload, and it can reach files in shared volumes. It does not restart the original container and does not change the pod spec that the application uses. Ephemeral containers cannot be removed from a pod once added, so the pod must be replaced to clear them.
- What it sees: Processes and network state of the running pod, depending on the sharing settings the pod uses. Confirm which namespaces are shared in your environment before relying on them.
- What it changes: Adds an ephemeral container entry to the pod object, which is recorded in the API audit trail.
- Distroless fit: Works well for images with no shell, because the debug image brings its own tools.
- Limits: It cannot help if the container is in a crash loop with no running process to attach to.
- Cleanup: Restarting or recreating the pod removes the debug container.
Before use, confirm that your cluster version supports ephemeral containers in the mode you plan to use and that your audit policy captures the change.
A pod copy creates a new pod from the failing pod's spec, with selected fields changed, such as the container image or the command. kubectl debug can produce this copy, which is the usual route for a container that crashes at startup or exits before you can attach to it. The original pod keeps its state, and the copy runs the process you choose so you can observe the startup path. Because the copy is a separate pod, its environment, volumes and service account match the original only for what was copied across.
- What it sees: The startup path under the new command, plus the same configuration, mounts and environment the copy inherits.
- What it changes: Creates a new pod that consumes resources and can reach the same secrets and services the original could.
- Image swap: Useful for replacing a broken image with a debug build or a shell-capable image to inspect files.
- Data risk: Copies that mount persistent volumes may write to live data, so mount read-only or use a snapshot where possible.
- Cleanup: Delete the copy once the investigation is complete, since it can hold credentials and create traffic.
Illustrative example: a payments pod that exits at startup can be copied with a shell entrypoint so the team can list the mounted configuration before the application runs. Check the copy's volumes and service account before it starts.
A node debugging session starts a pod on a chosen node with access to the host, which lets engineers inspect kubelet state, container runtime data, logs and the host filesystem. It is the right tool when the fault sits below the workload, such as a node that cannot pull images, a disk that is filling, or a network issue specific to one machine. Host access is powerful, so the session must be limited to a clear purpose and removed once the work ends. Node debugging does not reveal the internals of other nodes or the control plane unless those are reached separately.
- What it sees: Host processes, host paths and the node's view of containers and disks, depending on the access the session is granted.
- What it changes: Anything written to the host filesystem, so changes must be recorded and reverted.
- When it fits: Node-level symptoms that appear across several pods on the same machine.
- Risk: Host access can expose credentials and kubelet certificates, so limit who can start these sessions.
- Cleanup: Confirm the debug pod is deleted and that no host changes remain before the node returns to service.
Before use, confirm with your platform team which node debugging method your cluster version supports and how that access is audited.
Start with the question of where the fault sits. If the workload is running but misbehaving, an ephemeral container is the least invasive option because it leaves the pod spec alone. If the container dies before you can reach it, a pod copy with a changed command gives you a controlled way to observe startup. If several pods on one node fail together, the node is the likely boundary and a node session is justified. Each method leaves a different trail, so decide before work starts which evidence you need and who will review it.
- Least invasive first: Try attaching before copying, and copy before touching the node.
- Scope: Limit each session to one pod, one namespace or one node.
- Audit: Confirm that API audit logs record debug creation for the namespaces you control.
- Access: Restrict the RBAC verbs for ephemeral containers and node sessions to named roles.
- Record: Note the commands run, the time and the reason, so the incident review can follow the steps.
Ask your platform team to confirm the RBAC rules and audit settings in your environment before granting access to production workloads.
How the debug request flows from kubectl to the node
The request starts at the engineer's kubectl debug command and crosses the trust boundary at the API server, where authentication and RBAC decide whether the debug subresource is allowed. Once admitted, the API server updates the target pod (adding an ephemeral container or creating a copied pod) or, for node debugging, schedules a debugging pod on the chosen node. Every accepted request should leave an audit log record, so check that record first when a session is unexpectedly allowed or denied.
Debug requests pass the API server and RBAC check before reaching the node.
How to set up kubectl debug safely in a self-managed cluster
This sequence gives platform teams a tested way to let engineers debug distroless and crashing pods without widening access beyond what the work needs. It ends with a verified role, a pinned debug image and a node debugging path limited to a small group.
Confirm kubectl and API server versions are compatible
The platform team checks the kubectl version on each engineer's workstation and on the CI runner against the cluster's kube-apiserver version. The Kubernetes version skew policy governs which combinations are supported, and the kube-apiserver is the reference point, so the kubectl build should be within the supported range of that server. Run
kubectl versionagainst the target cluster and record both versions. The step is done when every client that will run debug commands reports a version inside the supported window, and any outliers are upgraded before access is granted.Choose and pin a debug image
The team selects one debug image that contains the shell, network and process tools engineers need, such as a maintained utility image with common troubleshooting binaries. Pin it to a specific tag or digest rather than a floating latest tag, and mirror it into the private registry if the cluster has no internet access, since the debug container pulls the image like any other workload. Confirm the image is approved by the security team, scanned, and that its tools fit the workloads you run. The step is done when the image reference is recorded in the team runbook and a test pull succeeds from a node in the cluster.
Create a scoped RBAC role for ephemeral containers
Define a Role in each namespace where debugging is allowed, granting the get and patch verbs on pods, and create on the pods/ephemeralcontainers subresource. Add pods/attach or pods/exec only if engineers need an interactive session into an existing container, and avoid broad wildcards on resources or verbs. For pod copies made with
kubectl debug --copy-to, grant create on pods in the same namespace and keep the list of users small. Bind the role to a named group from your identity provider. The step is done whenkubectl auth can-ireturns yes for the intended group and no for a standard developer account in an unrelated namespace.Restrict node debugging to a small group
Node debugging starts a privileged pod on a host with host namespaces mounted, so it should sit outside the general debugging role. Create a separate ClusterRole or namespace-bound role that allows creating pods in a dedicated admin namespace, and bind it only to a short named group approved by the platform owner. Check that the namespace enforces the Pod Security Standards level required for the debug pod, and document who can approve access. Audit logging should capture each node debug session. The step is done when only that group can run
kubectl debug nodeand the audit trail records the action.Confirm Pod Security Admission settings for debug workloads
Review the Pod Security Admission labels on the namespaces where debug pods run. The Restricted, Baseline and Privileged standards behave differently, and an ephemeral container or copied pod that adds capabilities or host access can be rejected or allowed depending on the label. Decide which namespaces permit the Baseline or Privileged level, keep application namespaces on stricter levels, and test the outcome before relying on it. The step is done when a deliberately non-compliant debug request is blocked in an application namespace and accepted only in the designated admin namespace.
Verify with a test pod and a distroless target
Deploy a small distroless test workload in a sandbox namespace, then attach an ephemeral container with
kubectl debug -itusing the pinned image and target the container's process namespace. Repeat withkubectl debugin copy mode, changing the image of one container, and confirm the copy runs without touching the original pod. Verify that a user outside the granted group receives a forbidden error. Record the commands and outputs in the runbook. The step is done when the ephemeral container, copied pod and forbidden check all behave as expected and the evidence is stored with the platform change record.Review and clean up debug artifacts
Ephemeral containers cannot be removed from a running pod, so they remain in the pod spec until it is recreated, and copied pods persist until someone deletes them. Set a team convention for deleting copied pods after a session, and check that the debug image and access lists are reviewed on the same cadence as other platform access. Confirm with your auditors which logs must be retained for debug sessions. The step is done when the cleanup procedure is documented, a leftover test copy has been removed, and the review owner is named.
What RBAC rights debugging actually requires
A debug session touches several permissions at once, and each one widens what a user can do inside a pod or on a node. The cards below cover the verbs and subresources to grant, the node-level paths that deserve the most caution, and how the namespace's Pod Security level limits what a debug container can run.
The pods/ephemeralcontainers subresource
Adding a debug container to a running pod is a write to the pods/ephemeralcontainers subresource, not to the pod itself. A user who can update the pod spec in general does not automatically hold this right, and the reverse is also true. Check it explicitly with a dry-run RBAC test before handing it to a team, and grant it only in the namespaces where that team runs workloads.
The create and get verbs on pods
kubectl debug needs get to read the target pod and create on the ephemeral containers subresource to attach a container. Copying a pod with --copy-to also needs create on pods, which lets the user define a new workload with a different image and settings. Treat create on pods as a broader grant than read access, because it lets the holder choose what runs.
Node debugging and nodes/proxy access
Debugging a node with kubectl debug node/ starts a pod that uses the host namespaces and a host filesystem mount, which is effectively root on that machine. The nodes/proxy subresource exposes the kubelet API and can run commands in any pod on the node. Grant either only to a small platform group, and confirm in your audit log that node debug sessions are recorded.
Pod Security levels and debug containers
Pod Security Admission applies the Privileged, Baseline or Restricted standard to each namespace, and it evaluates ephemeral containers as well as regular ones. A namespace enforcing Restricted will reject a debug container that asks for host networking, privilege escalation or a root user. Confirm the enforce level for every namespace where debug access is granted, because the level decides whether a debug session can do anything beyond reading.
Pod Security StandardsScoping these rights per namespace
Bind the debug role with a RoleBinding in each namespace rather than a ClusterRoleBinding, so a support engineer gets access only where the workloads they troubleshoot run. Namespace scope limits the blast radius if a credential leaks. Review bindings during access recertification, and remove them when a rotation or incident ends.
Questions teams ask before debugging access goes into production
How much effort does it take to set up debugging access for pods?
Effort depends less on the kubectl commands than on the access model around them. The commands themselves are short, but the work includes deciding which roles may attach ephemeral containers, which may create debug copies of pods, and which may open node debugging sessions, then writing those roles, testing them against real namespaces and documenting the procedure. Each of those steps is one-time work per cluster, with recurring effort when teams, namespaces or images change. Ask any partner to split the estimate into design, RBAC build, testing and handover so you can see where the time goes.
What does the work need from our platform team?
The platform team needs to provide cluster admin access for the build, a list of namespaces and teams that will use debugging, and a decision on who approves node-level access. They also need to confirm how users authenticate to the cluster, since RBAC bindings depend on group names from your identity provider. Expect the team to review role definitions, Pod Security Admission settings and audit log configuration, and to own the rollout in production. Confirm the time they must reserve for review before the work starts, because that is often the constraint.
Can our internal team set up debugging access alone?
Yes, if the team already runs Kubernetes RBAC, Pod Security Admission and audit logging in production and has someone who has written custom roles before. The hard parts are not the commands. They are restricting debug privileges so that a debug container cannot quietly grant host access, and proving that the controls work after an upgrade. Teams without that experience often succeed on a test cluster and then find gaps in production namespaces. A partner review or a short scoped engagement can cover that gap without taking over operations.
How long does a debugging access rollout take?
The duration depends on how many clusters and namespaces are involved, how many approval steps exist and how long your change process takes. A single cluster with a small set of namespaces moves faster than a fleet with separate policies per business unit. Ask for a timeline that lists design, test cluster validation, production change windows and user enablement as separate milestones, and confirm which ones depend on your own review or change board. Any timeline should be stated in the written scope, not as a general estimate.
What makes the work larger or smaller?
The main cost drivers are the number of clusters, the number of namespaces with different access rules, the number of identity groups that need separate roles, and audit requirements. Each additional cluster repeats the RBAC, admission and logging checks, and each separate compliance regime may require evidence that the controls work as described. Work gets smaller when clusters share a standard role model, when debugging is limited to a few namespaces, and when audit logs already flow to a central system. Ask a partner to show how each driver changes the quote.
Which permissions should a debug session need, and which should it never get?
Grant users the ability to create ephemeral containers only in the namespaces where they support workloads, and keep node debugging for a small group with a documented reason. Be cautious with privileged debug images, host namespaces and host path mounts, because those settings let a debug container reach the node. Pod Security Admission can limit what debug containers may run, and the Pod Security Standards describe the levels to compare against. Confirm the exact verbs and subresources in your Kubernetes version before writing roles, since debugging depends on the pods/ephemeralcontainers subresource.
Do debug sessions need audit logging, and what should it record?
Yes, audit logging should record who created a debug container or debug pod, when, in which namespace and with which image. Those events are sensitive because a debug session can read process memory and files from the target container. Confirm that your audit policy captures the relevant requests and that logs leave the cluster to a store your security team controls. Retention periods and review processes should come from your own policy, not from a default setting.
Security and audit risks of debug access
Debug access is powerful because it reaches into running workloads and nodes, which is exactly why it needs the same controls as production access. The risks below connect through one idea: a debug session can see, copy or run things that normal pod specs and image policies were meant to keep out of reach.
Debug containers bypass image policy
An ephemeral container is added to a running pod with its own image, and that image can be a general-purpose toolbox that your admission rules never reviewed as part of the workload. Pod Security Admission applies to the pod spec at admission, so confirm how your cluster enforces Baseline or Restricted on ephemeral containers and whether your policy engine evaluates them. Check which debug images are allowed and who can choose them.
Pod Security StandardsShared debug images leak secrets
Teams often share one debug image with curl, a shell and credential helpers baked in. If that image or its history contains tokens, kubeconfigs or internal endpoints, every engineer who pulls it inherits them. Keep debug images free of credentials, pin them by digest, and scan them like any other image in your registry.
Secrets exposed through pod environment
A debug container that shares the target's process namespace can read environment variables and mounted files of the target container. Secrets are stored unencrypted in etcd by default, and the Secrets good practices guidance asks administrators to configure encryption at rest and restrict list and watch access. Confirm that debug access does not reach secret-bearing containers in namespaces where users should not read them.
Secrets good practicesAudit logging of exec and attach
Creating an ephemeral container runs through the pods/ephemeralcontainers subresource, and exec and attach are recorded as their own requests. Set audit policy so these subresources are logged at a level that shows the user, target pod, container and image. Ask who reviews these entries and how long they are retained, because a session that leaves no record is hard to explain to an auditor.
Node-level access from debug sessions
Node debugging creates a pod that mounts the host filesystem and can share host namespaces, which makes it close to root on the node. Such pods are usually excluded from Restricted, so restrict who may create them with RBAC and a namespace that enforces a lower standard. Confirm which groups can run node debug, and remove the pod once the session ends.
When a debugging session is the wrong tool
Stop debugging interactively as soon as the same failure reproduces from a clean start. An ephemeral container from kubectl debug is good for answering a question about the running process: which files are present, what the environment holds, whether a DNS lookup or socket connection succeeds from the pod's network namespace. It is a poor place to repair a crash loop. Changes made inside a debug container or a copied pod disappear when the pod is recreated, and the copy you tested against may not match what your deployment pipeline will ship. When you find the cause, the fix belongs in the image, the manifest or the configuration that produced the pod, followed by a normal rollout. If the process fails only under its real startup arguments, reproduce those arguments in the copy instead of guessing at them.
Add logging before you add more access. Many failures on distroless or minimal images are visible if the application writes enough context: its configuration at startup, the dependency it could not reach, the file path it expected. Before you grant wider debugging rights, check whether kubectl logs --previous and the application's own log level already answer the question, and record what is missing so the next release emits it. Also consider that a failure may sit outside the container entirely. If lookups fail from every pod, work through the sibling topic on DNS resolution rather than repeatedly attaching to one workload. If nodes report NotReady or the API server itself misbehaves, stop at the cluster troubleshooting topic, because an ephemeral container cannot repair the control plane or the kubelet.
Restore from backup when the data itself is damaged. A debug session can show that a volume is corrupt or that a database refuses to start, but repairing state by hand in a live pod is rarely the right recovery path. Confirm that you have a recent, tested backup of the affected persistent volumes and, for cluster state, of etcd, and that you know how the restore is performed in your environment before you start changing things. Keep the debugging evidence (pod spec, events, logs and the outcome of each check) so the root cause can be fixed and the incident reviewed. Confirm the restore procedure, the backup tooling and its retention with your own platform team, since those details depend on how your clusters and storage are set up.
How DeployOpen scopes and delivers debugging access on Kubernetes
DeployOpen treats debugging access as part of the cluster's security design, not as an afterthought. We scope which debugging paths your teams need, build the RBAC and namespace controls that limit them, and document how engineers use them during incidents on clusters you control.
How we scope
- Inventory which workloads use distroless or minimal images that lack a shell and common tools.
- Define which roles may create ephemeral containers, copy pods or open node debugging sessions, and in which namespaces.
- Agree in writing which clusters, Kubernetes minor versions and access paths the fixed-scope engagement covers.
How we build
- Write least-privilege RBAC roles for pod ephemeral containers, pod copies and node debugging, and bind them to groups from your identity provider.
- Set up an approved debugging image catalog and check that Pod Security Admission settings still allow the intended debug workflow.
- Test each path on a non-production cluster, confirming what each role can and cannot do, and record the results.
How we hand over
- Deliver the role definitions, bindings and approved image list as versioned manifests your team can review and apply.
- Provide a runbook covering when to use ephemeral containers, when to copy a pod with a different image and when to avoid node sessions.
- Include audit log checks so your team can confirm who opened a debugging session and what they ran.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, so debugging roles can follow your Kubernetes upgrade plan.
- Re-verify RBAC and admission settings after each cluster change or minor version upgrade agreed in the scope.
- Confirm with your team which support hours, escalation paths and review cadence fit your operating model before work starts.

