11

I've recently started using NFS volumes for my clusters on-prem. This is the simplest and best solution for me, however it seems pretty limited in regards to the actual mounts options.

Is there anyway to set mount options on the node/cluster in the volume.yml files?

  • NFSv3
  • NFSv4/4.1
  • lookupcache
  • noatime
  • rsize,wsize

I have application that requires a specific version and also these mount options for performance.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 1Mi
  accessModes:
    - ReadWriteMany
  nfs:
    # FIXME: use the right IP
    server: 10.244.1.4
    path: "/"

Is there anyway to add mount flags here?

Bonn93
  • 163
  • 1
  • 1
  • 6

4 Answers4

12

It is possible and it's been GA in Kubernetes since 1.8.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#mount-options

https://github.com/kubernetes/enhancements/issues/168#issuecomment-317748159

John Blesener
  • 121
  • 1
  • 4
  • 1
    This question comes up in searches for users who want to specify mount options in Pod.spec.volumes, which is NOT supported. For those people, you can specify global mount options on the host by putting them in /etc/nfsmount.conf: https://man7.org/linux/man-pages/man5/nfsmount.conf.5.html – Mac Chaffee Sep 02 '22 at 16:15
12

If someone is looking for answers in 2021, here is what is working for me.

  mountOptions:
    - hard
    - timeo=600
    - retrans=3
    - proto=tcp
    - nfsvers=4.2
    - port=2050
    - rsize=4096
    - wsize=4096
    - noacl
    - nocto
    - noatime
    - nodiratime
user3702055
  • 129
  • 1
  • 2
1

Not really. Not supported by Kubernetes yet.

If you really need very specific NFS options, for now, I would recommend using hostPath.

This way you can mount your NFS volumes on a specific mount point on your host and have your Kubernetes pods use that.

Rico
  • 58,485
  • 12
  • 111
  • 141
  • 1
    Hmm, I thought that was the case. I guess building in some automation on the nodes could do this for now. Guess I'll follow the github requests. Thanks for the clarification! – Bonn93 Oct 03 '18 at 03:32
0

I am late in answering this question. But, I thought it might help someone who is looking for mentioning mountOptions their PV manifest. From the Kubernetes docs on PVs, I quote:

Mount options are not validated. If a mount option is invalid, the mount fails. In the past, the annotation volume.beta.kubernetes.io/mount-options was used instead of the mountOptions attribute. This annotation is still working; however, it will become fully deprecated in a future Kubernetes release.

I think its better to avoid specifying mountOptions and let the client (pod) and NFS server decide what's best when the mount happens. Secondly, as its going to be fully deprecated, so don't use it. I have been using NFS volumes without any of these parameters and it's working well.

Amit
  • 496
  • 7
  • 11
  • Note it is the annotation that is going deprecated, not the `mountOptions` spec option. – Oliver Gondža Nov 07 '22 at 12:07
  • NFS mount on client pod is failing if don't add `insecure` option in /etc/exports file for the shared directory. How did you resolve this issue on Kubernetes? Need help on this – Krishna Mar 10 '23 at 18:43