How to directly mount external NFS share/volume in kubernetes(1.10.3)

6/5/2018

I am using kubernetes : v1.10.3 , i have one external NFS server which i am able to mount anywhere ( any physical machines). I want to mount this NFS directly to pod/container . I tried but every time i am getting error. don't want to use privileges, kindly help me to fix.

ERROR: MountVolume.SetUp failed for volume "nfs" : mount failed: exit status 32 Mounting command: systemd-run Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/d65eb963-68be-11e8-8181-00163eeb9788/volumes/kubernetes.io~nfs/nfs --scope -- mount -t nfs 10.225.241.137:/stagingfs/alt/ /var/lib/kubelet/pods/d65eb963-68be-11e8-8181-00163eeb9788/volumes/kubernetes.io~nfs/nfs Output: Running scope as unit run-43393.scope. mount: wrong fs type, bad option, bad superblock on 10.225.241.137:/stagingfs/alt/, missing codepage or helper program, or other error (for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program) In some cases useful info is found in syslog - try dmesg | tail or so.

NFS server :  mount -t nfs 10.X.X.137:/stagingfs/alt   /alt    

I added two things for volume here but getting error every time.

first :

"volumeMounts": [
          {
            "name": "nfs",
            "mountPath": "/alt"
          }

        ],

Second :

 "volumes": [
  {
    "name": "nfs",
    "nfs": {
      "server": "10.X.X.137",
      "path": "/stagingfs/alt/"
    }
  }

],

---------------------complete yaml --------------------------------

{
  "kind": "Deployment",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "jboss",
    "namespace": "staging",
    "selfLink": "/apis/extensions/v1beta1/namespaces/staging/deployments/jboss",
    "uid": "6a85e235-68b4-11e8-8181-00163eeb9788",
    "resourceVersion": "609891",
    "generation": 2,
    "creationTimestamp": "2018-06-05T11:34:32Z",
    "labels": {
      "k8s-app": "jboss"
    },
    "annotations": {
      "deployment.kubernetes.io/revision": "2"
    }
  },
  "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "k8s-app": "jboss"
      }
    },
    "template": {
      "metadata": {
        "name": "jboss",
        "creationTimestamp": null,
        "labels": {
          "k8s-app": "jboss"
        }
      },
      "spec": {
          "volumes": [
      {
        "name": "nfs",
        "nfs": {
          "server": "10.X.X.137",
          "path": "/stagingfs/alt/"
        }
      }

    ],
        "containers": [
          {
            "name": "jboss",
            "image": "my.abc.com/alt:7.1_1.1",
            "resources": {},
            "volumeMounts": [
          {
            "name": "nfs",
            "mountPath": "/alt"
          }

        ],
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent",
            "securityContext": {
              "privileged": true
            }
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
      }
    },
    "strategy": {
      "type": "RollingUpdate",
      "rollingUpdate": {
        "maxUnavailable": "25%",
        "maxSurge": "25%"
      }
    },
    "revisionHistoryLimit": 10,
    "progressDeadlineSeconds": 600
  },
  "status": {
    "observedGeneration": 2,
    "replicas": 1,
    "updatedReplicas": 1,
    "readyReplicas": 1,
    "availableReplicas": 1,
    "conditions": [
      {
        "type": "Available",
        "status": "True",
        "lastUpdateTime": "2018-06-05T11:35:45Z",
        "lastTransitionTime": "2018-06-05T11:35:45Z",
        "reason": "MinimumReplicasAvailable",
        "message": "Deployment has minimum availability."
      },
      {
        "type": "Progressing",
        "status": "True",
        "lastUpdateTime": "2018-06-05T11:35:46Z",
        "lastTransitionTime": "2018-06-05T11:34:32Z",
        "reason": "NewReplicaSetAvailable",
        "message": "ReplicaSet \"jboss-8674444985\" has successfully progressed."
      }
    ]
  }
}

Regards Anupam Narayan

-- Anupam
docker
kubernetes

1 Answer

6/5/2018

As stated in the error log:

for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program

According to this question, you might be missing the nfs-commons package which you can install using sudo apt install nfs-common

-- yamenk
Source: StackOverflow