<p>I am mounting an <code>emptyDir</code> volume so it can be used for sharing files between containers running in the same pod. Lets say the mount point is called <code>/var/log/mylogs</code>. When I mount the <code>emptydir</code> all of the pre-existing files that were in mylogs get deleted. I know this is part of the Kubernetes functionality but I was wondering if there is a way to get around it? I <a href="https://medium.com/hackernoon/mount-file-to-kubernetes-pod-without-deleting-the-existing-file-in-the-docker-container-in-the-88b5d11661a6" rel="nofollow noreferrer">tried using subPath</a> but it looks like that only works for singular files.</p>

FestiveHydra235
<p>Consider using <code>PersistentVolumes</code> instead, since it serves as a long-term storage in your Kubernetes cluster. They exist beyond containers, pods, and nodes. A pod uses a persistent volume claim to to get read and write access to the persistent volume. <code>PersistentVolume</code> decouples the storage from the Pod. Its lifecycle is independent. It enables safe pod restarts and sharing data between pods.</p>
<blockquote>
<p>But will the pvc delete all of the existing contents? How would multiple files work with the subPath?</p>
</blockquote>
<p>Forget about finding any workaround using emptryDir or SubPath when you can easily use <code>PersistentVolumes</code>. Data persistence — a mechanism that keeps data even after the Pod is deleted — is required.</p>
<p>You can find more useful info about <code>PersistentVolumes</code> on <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">official documentation</a> or <a href="https://loft.sh/blog/kubernetes-persistent-volumes-examples-and-best-practices/" rel="nofollow noreferrer">here in a fresh new article</a></p>
