31

I have a Kubernetes setup installed in my Ubuntu machine. I'm trying to setup a nfs volume and mount it to a container according to this http://kubernetes.io/v1.1/examples/nfs/ document.

nfs service and pod configurations

kind: Service
apiVersion: v1
metadata:
  name: nfs-server
spec:
  ports:
    - port: 2049
  selector:
    role: nfs-server
---
apiVersion: v1
kind: Pod
metadata:
  name: nfs-server
  labels:
    role: nfs-server
spec:
  containers:
    - name: nfs-server
      image: jsafrane/nfs-data
      ports:
        - name: nfs
          containerPort: 2049
      securityContext:
        privileged: true

pod configuration to mount nfs volume

apiVersion: v1
kind: Pod
metadata:
  name: nfs-web
spec:
  containers:
    - name: web
      image: nginx
      ports:
        - name: web
          containerPort: 80
      volumeMounts:
          # name must match the volume name below
          - name: nfs
            mountPath: "/usr/share/nginx/html"
  volumes:
    - name: nfs
      nfs:
        # FIXME: use the right hostname
        server: 192.168.3.201
        path: "/"

When I run kubectl describe nfs-web I get following output mentioning it was unable to mount nfs volume. What could be the reason for that?

Name:               nfs-web
Namespace:          default
Image(s):           nginx
Node:               192.168.1.114/192.168.1.114
Start Time:         Sun, 06 Dec 2015 08:31:06 +0530
Labels:             <none>
Status:             Pending
Reason:             
Message:            
IP:             
Replication Controllers:    <none>
Containers:
  web:
    Container ID:   
    Image:      nginx
    Image ID:       
    State:      Waiting
      Reason:       ContainerCreating
    Ready:      False
    Restart Count:  0
    Environment Variables:
Conditions:
  Type      Status
  Ready     False 
Volumes:
  nfs:
    Type:   NFS (an NFS mount that lasts the lifetime of a pod)
    Server: 192.168.3.201
    Path:   /
    ReadOnly:   false
  default-token-nh698:
    Type:   Secret (a secret that should populate this volume)
    SecretName: default-token-nh698
Events:
  FirstSeen LastSeen    Count   From            SubobjectPath   Reason      Message
  ───────── ────────    ─────   ────            ─────────────   ──────      ───────
  36s       36s     1   {scheduler }                Scheduled   Successfully assigned nfs-web to 192.168.1.114
  36s       2s      5   {kubelet 192.168.1.114}         FailedMount Unable to mount volumes for pod "nfs-web_default": exit status 32
  36s       2s      5   {kubelet 192.168.1.114}         FailedSync  Error syncing pod, skipping: exit status 32
David Maze
  • 130,717
  • 29
  • 175
  • 215
Dimuthu
  • 7,946
  • 6
  • 22
  • 37
  • Related question: https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount/57141195#57141195 I gave a Kubernetes-related answer there, as I thought it was closer to the problem. – Bruno Medeiros Jul 22 '19 at 07:43

7 Answers7

45

I had the same problem, and I solved it by installing nfs-common in every Kubernetes nodes.

apt-get install -y nfs-common

My nodes were installed without nfs-common. Kubernetes will ask each node to mount the NFS into a specific directory to be available to the pod. As mount.nfs was not found, the mounting process failed.

Good luck!

KikoV
  • 899
  • 6
  • 13
  • 1
    Installing the nfs-common on every kubernetes node solved my problem! Thanks! – RazvanParautiu Apr 24 '20 at 09:32
  • 2
    Soooo... do you use a custom built docker image for this? Are you kubectl exec-ing into every single node to install? Are you altering a manifest to make sure it get's installed on initialisation of pods? Or does this really need to be on the _node_ itself? I guess I'm out of luck in that case with Docker for Mac. – Ambidex Oct 22 '20 at 11:39
  • For anyone on RHEL/CentOS, install nfs-utils instead. – Dunatotatos Apr 13 '22 at 08:40
1

It looks like volumes.nfs.server=192.168.3.201 is incorrectly configured on your client. It should be set to the ClusterIP address of your nfs-server Service.

1

I fixed this issue by installing nfs-utils on the worker nodes.

double-beep
  • 5,031
  • 17
  • 33
  • 41
xichen
  • 339
  • 2
  • 6
1

Had the same issue with NFS which only allowed root mounts. fixed by:

a. allow non-root users to mount NFS (on the server).

or

b. in PersistentVolume add

  mountOptions:
    - nfsvers=4.1
Pav K.
  • 2,548
  • 2
  • 19
  • 29
  • Adding the `mountOptions` did not fix my issue. I am using AWS EFS – alltej Jan 31 '20 at 19:50
  • Above worked for manually setup linux nfs servers. For EFS You probably can get exact instructions from aws docs. – Pav K. Feb 03 '20 at 13:56
  • editing /etc/exports file to enable non-root users to mount NFS shared path fixed my case. I added **no_root_squash** for that. My configuration looks something like /mnt/storage x.x.x.x (rw,sync,no_root_squash,no_subtree_check) – daniel rubambura Jun 20 '20 at 16:35
1

In my case the issue was that i hadn't declared the host server of the nfs in the /etc/exports file. After adding an entry in there for my host server, the volume was working correctly.

if you modify the file in anyway then you need restart the service too;

sudo systemctl restart nfs-kernel-server

An example of an entry in the /etc/exports file;

/var/nfs/home   192.111.222.333(rw,sync,no_subtree_check)
zaf187
  • 505
  • 4
  • 9
0

In my case, the issue was the folder defined in volume hostPath was not created in the local. Once the folder was created in the worker node server, the issue was addressed.

  Warning  FailedMount  3m18s                 kubelet            Unable to attach or mount volumes: unmounted volumes=[temp-volume], unattached volumes=[nfsvol-vre-data temp1-volume consumer1-serviceaccount-token-sdfsdf nfsvol]: timed out waiting for the condition
  Warning  FailedMount  71s (x10 over 5m20s)  kubelet            MountVolume.SetUp failed for volume "temp-volume" : hostPath type check failed: /tmp/folder is not a directory
  Warning  FailedMount  63s                   kubelet            Unable to attach or mount volumes: unmounted volumes=[temp-volume], unattached volumes=[nfsvol nfsvol-vre-data temp1-volume consumer1-serviceaccount-token-sdfsdf]: timed out waiting for the condition
Chance
  • 405
  • 4
  • 8
0

You need to execute the following on each master and node

sudo yum install nfs-utils -y
Tonny
  • 41
  • 2