5

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?

2 Answers 2

7

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"]

1
-1

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

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
    Commented Oct 15, 2019 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .