0

I have a pod (whose deployment config I have included below whichever I guessed as relevant to this question. Please tell me if more is needed) which uses a persistent volume. And the container is a docker whose docker file creates this folder /mounted/folder and also some hierarchy of subfolders. After this pod is deployed, I can see that this /mounted/folder is wiped clean of all the subfolders. I saw this question where it was mentioned that adding subPath field will ensure that the folder contents are not deleted. But it didn't work. I may have to mention here that I have another pod using the same pvc which this pod is using (for having a common shared storage). When this subPath didn't work, I tried (unsuccessfully) to add subPath in that pod deployment also. Please help! Thanks!

spec:
  containers:
    - name: nginx
      image: docker-registry-address/imagename:version
      volumeMounts:
        - mountPath: /mounted/folder
          subPath: folder
          name: name-of-volume

  volumes:
    - name: name-of-volume
      persistentVolumeClaim:
        claimName: pv-claim
aniztar
  • 2,443
  • 4
  • 18
  • 24
  • hi aniztar, does the container image contain a VOLUME definition? – ckaserer Sep 23 '20 at 11:26
  • Kubernetes always mounts the contents of the persistent volume over the content of the image, even if the volume is empty. It doesn't replicate Docker's unusual behavior of copying image content into empty named volumes (this also doesn't work with Docker bind mounts, and the volume content will always take precedence over the image content even if the image changes later). – David Maze Sep 23 '20 at 14:46
  • @ckaserer the docker container doesn't have a volume other than the one Kubernetes is supposed to provide with above config – aniztar Sep 24 '20 at 07:56
  • @DavidMaze: you are correct. however a Dockerfile with a volume definition before adding files to the location can result in an empty volume. – ckaserer Sep 24 '20 at 09:38
  • @aniztar can you provide us with `docker image history --no-trunc imagename:version` of your container image in the question? – ckaserer Sep 24 '20 at 09:39

0 Answers0