<p>There is a container in my Kubernetes cluster which I want to debug.</p>
<p>But there is no<code>netstat</code>, no <code>ip</code> and no <code>apk</code>.</p>
<p>Is there a way to upgrade this image, so that the common tools are installed?</p>
<p>In this case it is the nginx container image in a K8s 1.23 cluster.</p>

<p>Alpine is a stripped-down version of the image to reduce the footprint. So the absence of those tools is expected. Although since <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-running-pod/#debugging-using-a-copy-of-the-pod" rel="nofollow noreferrer">Kubernetes</a> <code>1.23</code>, you can use the <code>kubectl debug</code> command to attach a debug pod to the subject pod.
Syntax:</p>
<pre><code>kubectl debug -it &lt;POD_TO_DEBUG&gt; --image=ubuntu --target=&lt;CONTAINER_TO_DEBUG&gt; --share-processes
</code></pre>
<p>Example:
In the below example, the <code>ubuntu</code> container is attached to the Nginx-alpine pod, requiring debugging. Also, note that the <code>ps -eaf</code> output shows nginx process running and the <code>cat /etc/os-release</code> shows ubuntu running. The indicating process is shared/visible between the two containers.</p>
<pre><code>ps@kube-master:~$ kubectl debug -it nginx --image=ubuntu --target=nginx --share-processes
Targeting container &quot;nginx&quot;. If you don't see processes from this container, the container runtime doesn't support this feature.
Defaulting debug container name to debugger-2pgtt.
If you don't see a command prompt, try pressing enter.
root@nginx:/# ps -eaf
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 19:50 ?        00:00:00 nginx: master process nginx -g daemon off;
101           33       1  0 19:50 ?        00:00:00 nginx: worker process
101           34       1  0 19:50 ?        00:00:00 nginx: worker process
101           35       1  0 19:50 ?        00:00:00 nginx: worker process
101           36       1  0 19:50 ?        00:00:00 nginx: worker process
root         248       0  1 20:00 pts/0    00:00:00 bash
root         258     248  0 20:00 pts/0    00:00:00 ps -eaf
root@nginx:/# 
</code></pre>
<p>Debugging as ubuntu as seen here, this arm us with all sort of tools:</p>
<pre><code>root@nginx:/# cat /etc/os-release
NAME=&quot;Ubuntu&quot;
VERSION=&quot;20.04.3 LTS (Focal Fossa)&quot;
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=&quot;Ubuntu 20.04.3 LTS&quot;
VERSION_ID=&quot;20.04&quot;
HOME_URL=&quot;https://www.ubuntu.com/&quot;
SUPPORT_URL=&quot;https://help.ubuntu.com/&quot;
BUG_REPORT_URL=&quot;https://bugs.launchpad.net/ubuntu/&quot;
PRIVACY_POLICY_URL=&quot;https://www.ubuntu.com/legal/terms-and-policies/privacy-policy&quot;
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
root@nginx:/# 
</code></pre>
<p>In case ephemeral containers need to be enabled in your cluster, then you can enable it via feature gates as described <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/" rel="nofollow noreferrer">here</a>.</p>
