Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

volumeMount subPath doesn't work

Tags:

kubernetes

I'm trying to make use of the new subPath feature implemented in this pull request (recently released in v1.3).

However, the output of mount shows it ignoring the subPath, mounting the same NFS directory for both volume mounts:

nfs-server:/mnt/nfs/exports/apps/my-app on /home/share/foo type nfs4 (rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.128.0.4,local_lock=none,addr=nfs-server)
nfs-server:/mnt/nfs/exports/apps/my-app on /home/share/bar/baz type nfs4 (rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.128.0.4,local_lock=none,addr=nfs-server)

The relevant bits of my deployment YAML:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app
    spec:
      containers:
      - name: app
        image: my-org/my-app:latest
        volumeMounts:
        - mountPath: /home/share/foo
          name: nfs
          subPath: foo-resources
        - mountPath: /home/share/bar/baz
          name: nfs
          subPath: baz-resources
      volumes:
      - name: nfs
        nfs:
          path: /mnt/nfs/exports/apps/my-app
          server: nfs-server
like image 792
Nick Avatar asked Oct 19 '22 04:10

Nick


1 Answers

I'm not 100% sure about this, as I'm using a configMap volume rather than NFS, but I had to make the mountPath match the subPath as seen below before it worked for me.

FYI, I'm using Kubernetes v1.4.5.

If I'm reading this correctly, you are wanting to:

  • Mount the NFS file or directory /mnt/nfs/exports/apps/my-app/foo-resources such that it's path in the container is /home/share/foo/foo-resources.
  • Mount, the NFS file or directory /mnt/nfs/exports/apps/my-app/baz-resources such that it's path in the container is /home/share/bar/baz/baz-resources.

Try this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app
    spec:
      containers:
      - name: app
        image: my-org/my-app:latest
        volumeMounts:
        - mountPath: /home/share/foo/foo-resources
          name: nfs
          subPath: foo-resources
        - mountPath: /home/share/bar/baz/baz-resources
          name: nfs
          subPath: baz-resources
      volumes:
      - name: nfs
        nfs:
          path: /mnt/nfs/exports/apps/my-app
          server: nfs-server

The differences:

16c16
<         - mountPath: /home/share/foo/foo-resources
---
>         - mountPath: /home/share/foo
19c19
<         - mountPath: /home/share/bar/baz/baz-resources
---
>         - mountPath: /home/share/bar/baz
like image 101
damick Avatar answered Oct 21 '22 06:10

damick