<p>I have a Kubernetes POD running and I have attached a PVC to it. 
The PVC volume is /opt/stackstorm. </p>

<p>By default, there are certain files inside the /opt/stackstorm which comes as part of the docker official image. These files are visible when there is no PVC attached to the POD. </p>

<p>But when a PVC is attached, the files are replace and a lost&amp;found directory is created. </p>

<p>How we can retain the directory even after attaching the PVC ?</p>

<p>I have changed directories for the PVC.  When I change the directory from opt/stackstorm to /opt/stack then /opt/stackstorm has all the details but /opt/stack becomes empty. </p>

<p>So the PVC when attached to a POD is creating issue. </p>

<p>pvc.yaml:</p>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: stacke
  annotations:
    volume.beta.kubernetes.io/storage-class: "ebs"
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

deployment.yaml:

       volumeMounts:
          - name: stacke
            mountPath: /opt/stackstorm
      volumes:
      - name: stacke
        persistentVolumeClaim:
          claimName: stacke
      imagePullSecrets:
      - name: regcred
</code></pre>

<p>expected results is that /opt/stackstorm should have all the files as part of the image.</p>

sunil
<p>you can copy the the content of /opt/stackstorm to a new directory in dockerfile and build a new image . After that you can copy the content of the new directory back to /opt/stackstorm in run time. All of this issue occurred because this directory get initialized in build time .
For copying in run time you can use <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">postStart</a> in container lifecycle in kubernetes .
for example :<code>
spec:
      containers:
        - name: ....
          image: ....
          lifecycle:
            postStart:
              exec:
                command: ["cp" , "-r" , "/test/" ,"/opt/stackstorm"]
</code>
this command run after the container start .
but this approach copy every time the pod start , if you want to avoid this you can delete the content of the /opt/stackstorm in dockerfile in build time and then in postStart command write the script to check if this dir is empty do copying .
And you can have /opt/stackstorm as mountPath and attach a pvc to it just like you have done.</p>
