<p>I am using k8s with version 1.11 and CephFS as storage.</p>

<p>I am trying to mount the directory created on the CephFS in the pod. To achieve the same I have written the following volume and volume mount config
in the deployment configuration</p>

<p>Volume</p>

<pre><code>{
  "name": "cephfs-0",
  "cephfs": {
    "monitors": [
      "10.0.1.165:6789",
      "10.0.1.103:6789",
      "10.0.1.222:6789"
    ],
    "user": "cfs",
    "secretRef": {
      "name": "ceph-secret"
    },
    "readOnly": false,
    "path": "/cfs/data/conf"
  }
}
</code></pre>

<p>volumeMounts</p>

<pre><code>{
  "mountPath": "/opt/myapplication/conf",
  "name": "cephfs-0",
  "readOnly": false
} 
</code></pre>

<p>Mount is working properly. I can see the ceph directory i.e. /cfs/data/conf getting mounted on  /opt/myapplication/conf but following is my issue.</p>

<p>I have configuration files already present as a part of docker image at the location /opt/myapplication/conf. When deployment tries to mount the ceph volume then all the files at the location /opt/myapplication/conf gets disappear. I know it's the behavior of the mount operation but is there any way by which I would be able to persist the already existing files in the container on the volume which I am mounting so that other pod which is mounting the same volume can access the configuration files. i.e. the files which are already there inside the pod at the location /opt/myapplication/conf should be accessible on the CephFS at location /cfs/data/conf.</p>

<p>Is it possible?</p>

<p>I went through the docker document and it mentions that </p>

<blockquote>
  <p>Populate a volume using a container
  If you start a container which creates a new volume, as above, and the container has files or directories in the directory to be mounted (such as /app/ above), the directory’s contents are copied into the volume. The container then mounts and uses the volume, and other containers which use the volume also have access to the pre-populated content.</p>
</blockquote>

<p>This matches with my requirement but how to achieve it with k8s volumes?</p>

<p>Unfortunately Kubernetes' volume system differs from Docker's, so this is not possible directly.</p>
<p>However, in case of a single file <code>foo.conf</code> you can use:</p>
<ul>
<li>a <code>mountPath</code> ending in this file name and</li>
<li>a <code>subPath</code> containing this file name, like this:</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>    volumeMounts:
    - name: cephfs-0
      mountPath: /opt/myapplication/conf/foo.conf
      subPath: foo.conf
</code></pre>
<p>Repeat that for each file. But if you have a lot of them, or if their names can vary, then you have to handle this at runtime or use templating tools. Usually that means mounting it somewhere else and setting up symlinks before your main process starts.</p>
