K8S: It is possible to use disk of one node as cluster shared storage?

5/13/2020

I have two PC avaliable at home, and want to make testlab for K8S.

One PC have big drive, so i think about use that store as avaliable for both nodes. most info i found is about local storage or fully external storage.

ideally i want to have full k8s solution, which can be autoscaled via deployment(just need one more node with needed affinity and it will be scaled there as well).

So, it is possible? any guides how to do that?

-- A. Kostromtsov
kubernetes

1 Answer

5/14/2020

Like it was already mentioned by @David Maze, there is no native way in Kubernetes for sharing nodes storage.

What you could do is setup a NFS storage on the node which has the highest storage and share it across the pod. You could setup the NFS inside the k8s cluster as a pod using Docker NFS Server. The NFS pod might be looking like this:

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

You will also have to expose the pod using a service:

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
      protocol: UDP

Once done you will be able to use it for any pod in the cluster:

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

This is fully described at Kubernetes Volumes Guide by Matthew Palmer also you should read Deploying Dynamic NFS Provisioning in Kubernetes.

-- Crou
Source: StackOverflow