<p>What is the best way to mount an external directory in a pod such that:</p>

<ol>
<li>the pod access to the directory is readonly</li>
<li>whole directory tree is accessible in the pod</li>
<li>any change to the directory contents or creation of new files and directories in this directory is reflected to the pod instantly</li>
<li>all replicas of the pod see the same directory tree</li>
</ol>

<p>Apparently any solution with ConfigMaps does not satisfy conditions 2 and 3.</p>

Nimsa
<p>Using configMap-s one can achieve all requirements (1) thru (4) except for part of (3) - changes to existing files content (by changing their configMap-s) will be reflected in the pods (almost) instantly but new files or directories won't.</p>

<p>The following script - see <a href="https://github.com/apimastery/APISimulator/blob/master/kubernetes-deployment/apisim-kubernetes-deploy.sh" rel="nofollow noreferrer">here</a> - implements the approach.</p>

<p>Notice that:</p>

<ul>
<li>(1) is now the default starting with 1.9.6 - see <a href="https://github.com/kubernetes/kubernetes/issues/62099" rel="nofollow noreferrer">this</a> for a discussion. </li>
<li>Key for (2) is the use of <a href="https://kubernetes.io/docs/concepts/storage/volumes/#projected" rel="nofollow noreferrer">projected volumes</a>.</li>
<li>(4) is out-of-the-box feature as documented <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#mounted-configmaps-are-updated-automatically" rel="nofollow noreferrer">here</a>, except for when using subPath.</li>
<li>Using a single configMap for all files may cause "...ERROR: The ConfigMap "" is invalid: []: Too long: must have at most 1048576 characters".</li>
<li>Using a configMap per file also has a size limitation of ~1MB for the file content (it is an etcd limitation).</li>
</ul>
