How to specify mountOptions on an existing NFS share

4/17/2018

We're creating a kubernetes statefulset that is mounting a pre-existing NFS share.

Here's a trimmed down example:

apiVersion: apps/v1beta2
kind: StatefulSet
metadata: 
  name: hostname
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: container
        image: 4730230466298.dkr.ecr.us-east-1.amazonaws.com/container:latest
        volumeMounts:
        - name: efs
          mountPath: /efs
          readOnly: true
      volumes:
      - name: efs
        nfs:
          path: /
          server: 10.33.1.90
          readOnly: true

This works fine, and the nfs volume is correctly mounted into the container. But how can I specify the mount options on the the mount? I've tried setting the mountOptions parameter as shown here: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#mount-options

on the volume and the volumeMount and it fails to validate. I don't need (or want) to create a PV or PVC because the nfs volume already exists outside of k8s and I just need to use it.

Is there anyway to specify the mount options?

-- user1522264
kubernetes
statefulset

1 Answer

4/18/2018

You are adding PersistentVolumes's specs into template.spec.volumes (Pos's volume).

These two are not the same thing. The correct reference for this template.spec.volumes would be https://kubernetes.io/docs/concepts/storage/volumes/

You can create a PersistentVolume and persistenVolumeClaim with proper mountOptions, then you can use that pvc in the volume field in your above yaml.

Here is some example of nfs volume given by kubernetes itself.

-- Abdullah Al Maruf - Tuhin
Source: StackOverflow