<p>I have a python pod running.
This python pod is using different shared libraries. To make it easier to debug the shared libraries I would like to have the libraries directory on my host too.
The python dependencies are located in <code>/usr/local/lib/python3.8/site-packages/</code> and I would like to access this directory on my host to modify some files.</p>
<p>Is that possible and if so, how? I have tried with <code>emptyDir</code> and <code>PV</code> but they always override what already exists in the directory.</p>
<p>Thank you!</p>

Jérémy Octeau
<p>This is by design. Kubelet is responsible for preparing the mounts for your container. At the time of mounting they are empty and kubelet has no reason to put any content in them.</p>
<p>That said, there are ways to achieve what you seem to expect by using init container. In your pod you define init container using your docker image, mount your volume in it in some path (ie. <em>/target</em>) but instead of running regular content of your container, run something like</p>
<pre><code>cp -r /my/dir/* /target/ 
</code></pre>
<p>which will initiate your directory with expected content and exit allowing further startup of the pod
Please take a look: <a href="https://stackoverflow.com/questions/51739517/how-to-avoid-override-the-container-directory-when-using-pvc-in-kubernetes">overriding-directory</a>.</p>
<p>Another option is to use <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">subPath</a>. Subpath references files or directories that are controlled by the user, not the system. Take a loot on this example how to mount single file into existing directory:</p>
<pre><code>---
        volumeMounts:
        - name: &quot;config&quot;
          mountPath: &quot;/&lt;existing folder&gt;/&lt;file1&gt;&quot;
          subPath: &quot;&lt;file1&gt;&quot;
        - name: &quot;config&quot;
          mountPath: &quot;/&lt;existing folder&gt;/&lt;file2&gt;&quot;
          subPath: &quot;&lt;file2&gt;&quot;
      restartPolicy: Always
      volumes:
        - name: &quot;config&quot;
          configMap:
            name: &quot;config&quot;
---

</code></pre>
<p>Check full example  <a href="https://gist.github.com/tuannvm/0fc6e94a3759c91b1abe71c149152f77" rel="nofollow noreferrer">here</a>. See: <a href="https://stackoverflow.com/questions/39751421/mountpath-overrides-the-rest-of-the-files-in-that-same-folder">mountpath</a>, <a href="https://stackoverflow.com/questions/33415913/whats-the-best-way-to-share-mount-one-file-into-a-pod">files-in-folder-overriding</a>.</p>
<p>You can also as @DavidMaze said debug your setup in a non-container Python virtual environment if you can, or as a second choice debugging the image in Docker without Kubernetes.</p>
