4

We have an in house Kubernetes cluster running on bare-metal, can I set up an NFS server on one of the nodes (either worker or master) in the cluster? If yes do I need to change anything in the cluster?

AVarf
  • 409
  • 1
  • 6
  • 17

2 Answers2

6

You can setup a pod that will act as NFS server.

There is a ready image on Docker Hub cpuguy83/nfs-server.

To use it you need to created a service to expose the NFS server to pods inside the cluster:

kind: Service
apiVersion: v1
metadata:
  name: nfs-service
spec:
  selector:
    role: nfs
  ports:
    # Open the ports required by the NFS server
    # Port 2049 for TCP
    - name: tcp-2049
      port: 2049
      protocol: TCP

    # Port 111 for UDP
    - name: udp-111
      port: 111

And a pod which will run the image:

kind: Pod
apiVersion: v1
metadata:
  name: nfs-server-pod
  labels:
    role: nfs
spec:
  containers:
    - name: nfs-server-container
      image: cpuguy83/nfs-server
      securityContext:
        privileged: true
      args:
        # Pass the paths to share to the Docker image
        - /exports

An example of a pod using the NFS volume:

kind: Pod
apiVersion: v1
metadata:
  name: pod-using-nfs
spec:
  # Add the server as an NFS volume for the pod
  volumes:
    - name: nfs-volume
      nfs: 
        # URL for the NFS server
        server: 10.108.211.244 # Change this!
        path: /

  # In this container, we'll mount the NFS volume
  # and write the date to a file inside it.
  containers:
    - name: app
      image: alpine

      # Mount the NFS volume in the container
      volumeMounts:
        - name: nfs-volume
          mountPath: /var/nfs

      # Write to a file inside our NFS
      command: ["/bin/sh"]
      args: ["-c", "while true; do date >> /var/nfs/dates.txt; sleep 5; done"]

Crou
  • 714
  • 3
  • 9
  • There appears to be issues with using domain names to resolve the NFS pod https://github.com/kubernetes/minikube/issues/3417#issuecomment-493366877 – brettinternet Sep 03 '22 at 04:27
-1

Look at the NFS-Client Provisioner: https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client

am4
  • 1
  • 1
    Thank you for your answer. I decided to go with StorageOS which takes care of everything and it can be run on cloud too but for my personal information I like to ask: Your link is just an NFS client and we need to pass the IP of the server to it, my question is can I put that server on one of the nodes or this is a bad prctice? – AVarf Oct 15 '19 at 11:19