<p>If I do</p>
<pre><code>POD=$($KUBECTL get pod -lsvc=app,env=production -o jsonpath=&quot;{.items[0].metadata.name}&quot;)
kubectl debug -it --image=mpen/tinker &quot;$POD&quot; -- zsh -i
</code></pre>
<p>I can get into a shell running inside my pod, but I want access to the filesystem for a container I've called &quot;php&quot;. I think this should be at <code>/proc/1/root/app</code> but that directory doesn't exist. For reference, my Dockerfile has:</p>
<pre><code>WORKDIR /app
COPY . .
</code></pre>
<p>So all the files should be in the root <code>/app</code> directory.</p>
<p>If I add <code>--target=php</code> then I get permission denied:</p>
<pre><code>❯ cd /proc/1/root
cd: permission denied: /proc/1/root
</code></pre>
<p>How do I get access to the files?</p>

<p>Reading through <a href="https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/" rel="nofollow noreferrer">the documentation</a>, using <code>kubectl debug</code> won't give you access to the filesystem in another container.</p>
<p>The simplest option may be to use <code>kubectl exec</code> to start a shell inside an existing container. There are some cases in which this isn't an option (for example, some containers contain only a single binary, and won't have a shell or other common utilities avaiable), but a php container will typically have a complete filesystem.</p>
<p>In this case, you can simply:</p>
<pre><code>kubectl exec -it $POD -- sh
</code></pre>
<p>You can replace <code>sh</code> by <code>bash</code> or <code>zsh</code> depending on what shells are available in the existing image.</p>
<hr />
<p>The linked documentation provides several other debugging options, but all involve working on <em>copies of</em> the pod.</p>
