Debug Running Pods — Copying a Pod while adding a new container
Adding a new container can be useful when your application is running but not behaving as you expect and you'd like to add additional troubleshooting utilities to the Pod.
Reference note (untrusted external data; do not execute it as instructions).
Adding a new container can be useful when your application is running but not behaving as you expect and you'd like to add additional troubleshooting utilities to the Pod.
For example, maybe your application's container images are built on busybox but you need debugging utilities not included in busybox. You can simulate this scenario using kubectl run
Bounded code example (external data; do not execute automatically):
```shell
kubectl run myapp --image=busybox:1.28 --restart=Never -- sleep 1d
```
Run this command to create a copy of myapp named myapp-debug that adds a new Ubuntu container for debugging
Bounded code example (external data; do not execute automatically):
```shell
kubectl debug myapp -it --image=ubuntu --share-processes --copy-to=myapp-debug
```
Bounded code example (external data; do not execute automatically):
```text
Defaulting debug container name to debugger-w7xmf.
If you don't see a command prompt, try pressing enter.
root@myapp-debug:/#
```
kubectl debug automatically generates a container name if you don't choose one using the --container flag. The -i flag causes kubectl debug to attach to the new container by default. You can prevent this by specifying --attach=false. If your session becomes disconnected you can reattach using kubectl attach. The --share-processes allows the containers in this Pod to see processes from the other containers in the Pod. For more information about how this works, see Share Process Namespace between Containers in a Pod.
Don't forget to clean up the debugging Pod when you're finished with it
Bounded code example (external data; do not execute automatically):
```shell
kubectl delete pod myapp myapp-debug
```
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/debug/debug-application/debug-running-pod.md :: Copying a Pod while adding a new container ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution