9

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
  • 123
  • 1
  • 1
  • 5

1 Answers1

1

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.

  • Thank you, I'll give this a try and see if I can get it working. Will then follow up here. – user1522264 Apr 19 '18 at 22:28
  • 1
    The issue with the example given is that it uses the absolute minimal set of options and gives no reference to other options. If you're wanting to mount 2 NFS shares then its of no use at all. If it included things like storage classes etc then it would make it a reasonable example – Timothy c Oct 16 '19 at 08:09