<p>I have a pod that reads from an image that contains data within <code>var/www/html</code>.  I want this data to be stored in a persistent volume.  This is my deployment yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
    name: app
spec:
    replicas: 1
    selector:
        matchLabels:
            container: app
    template:
        metadata:
            labels:
                container: app
        spec:
            containers:
                - name: app
                  image: my/toolkit-app:working
                  ports:
                      - containerPort: 80
                  volumeMounts:
                      - mountPath: /var/www/html
                        name: toolkit-volume
                        subPath: html
            volumes:
                - name: toolkit-volume
                  persistentVolumeClaim:
                      claimName: azurefile
            imagePullSecrets:
                - name: my-cred
</code></pre>
<p>However when I look into the pod I can see the directory is empty:</p>
<p><a href="https://i.stack.imgur.com/Uw6AN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uw6AN.png" alt="Empty directory" /></a></p>
<p>If I comment out the persistent volume:</p>
<pre><code>              #volumeMounts:
              #    - mountPath: /var/www/html
              #      name: toolkit-volume
              #      subPath: html
</code></pre>
<p>I can see that the image data is there:</p>
<p><a href="https://i.stack.imgur.com/BMeBA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BMeBA.png" alt="Non-empty directory" /></a></p>
<p>So it seems like the persistent volume is overwriting the existing directory - is there a way round this? Ideally I want <code>/var/www/html</code> to be stored in a separate volume and for any existing files within the image to be stored there too.</p>

<p>This is more a problem of visibility: If you mount an empty volume at a specific path, you won't be able to see, what was placed there in the container image.</p>
<p>From your question I assume that you want to be able to rollout updates by the means of a new container image, but at the same time retain variable data, that was created at the same directory from your application.</p>
<p>You could achieve this with the following method:
Use an init container with the same image and mount your persistent directory to a different path, for example <code>/data</code>
As command for the init container copy the contents of <code>/var/www/html</code> to <code>/data</code>.</p>
<p>In the regular container image use the mount you already have, it will contain your variable data and the updated data from the init container.</p>
