<p>I have these volume mounts right now defined in my deployment,</p>
<pre><code>volumeMounts:
        - name: website-storage
          mountPath: /app/upload
          readOnly: false
          subPath: foo/upload
        - name: website-storage
          mountPath: /app/html
          readOnly: true
          subPath: foo/html/html
</code></pre>
<p>Now I want to mount another path from my PVC into <code>/app/html/website-content</code> and this is what I attempted with,</p>
<pre><code>volumeMounts:
        - name: website-storage
          mountPath: /app/upload
          readOnly: false
          subPath: foo/upload
        - name: website-storage
          mountPath: /app/html
          readOnly: true
          subPath: foo/html/html
        - name: website-storage
          mountPath: /app/html/website-content
          readOnly: true
          subPath: foo/website-content
</code></pre>
<p>This does not work and gives an error during mounting. Is it possible to do this? Do I have to explicitly create the <code>website-content</code> folder prior to mounting it? Thanx in advance!</p>

Gayan Jayasingha
<p>The cause of the issue is that during pod initialization there is an attempt to create directory <code>website-content</code> in the <code>/app/html</code> location which will cause error as the <code>/app/html</code> is mounted read only.</p>
<p>You cannot create a folder in the read only system that means you can't mount a volume as the folder doesn't exist, but if there was already the folder created, you can mount the volume.</p>
<p>So all you need is just to create a directory <code>website-content</code> in the <code>foo/html/html</code> location on the volume before you attach it into container. Then, as it will be mounted to the <code>/app/html</code> location, there will be directory <code>/app/html/website-content</code>.</p>
<p>For example, you can use a <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a> for that. Add this code to your deployment file:</p>
<pre><code>initContainers:
  - name: init-container
    image: busybox
    volumeMounts:
    - name: website-storage
      mountPath: /my-storage
      readOnly: false
    command: ['sh', '-c', 'mkdir -p /my-storage/foo/html/html/website-content']
</code></pre>
<p>When the pod is running, you check mount points on the pod using <code>kubectl describe pod {pod-name}</code>:</p>
<blockquote>
<pre><code>Mounts:
/app/html from website-storage (ro,path=&quot;foo/html/html&quot;)
/app/html/website-content from website-storage (ro,path=&quot;foo/website-content&quot;)
/app/upload from website-storage (rw,path=&quot;foo/upload&quot;)
</code></pre>
</blockquote>
