Kubernetes - use local hard drive as persistent volume

12/4/2018

I have set up a a two node cluster on Raspberry pi. I was wondering if it would be possible to make a hard drive connected to the master node as the persistent volume ? I am unable to find any options in the documentation.

Any suggestions or directions is much appreciated.thanks

-- IT_novice
kubernetes

1 Answer

12/4/2018

hostPath volume Type

The hostPath volume type is single-node only, meaning that a pod on one node cannot access the hostPath volume on another node. One way to get around this limitation may be to either create a StatefulSet or Daemonset which could force pods to always deploy to the same node(s), or force a deployment's pods to always be deployed to the same node via a nodeSelector.

If you are circumventing the hostPath single-node limitation via nodeSelector while using multiple pods on the same node beware of the following issue:

Multiple Kubernetes pods sharing the same host-path/pvc will duplicate output

Alternative Volume Types

If you do not wish to circumvent the limitation of the hostPath volume type, you should look into other volume types such as NFS or Gluster, both of which you can setup locally, but require some additional configuration and setup.

If you have only one drive which you can attach to one node, I think you should use the basic NFS volume type as it does not require replication.

If however, you can afford another drive to plug in to the second node, you can take advantage of GlusterFS's replication feature.

Volume Types

NFS: https://kubernetes.io/docs/concepts/storage/volumes/#nfs

GlusterFS: https://kubernetes.io/docs/concepts/storage/volumes/#glusterfs

Converting a drive to a volume:

As for making your hard-drive become a persistent volume, I would separate that into 2 tasks.

  1. You need mount your physical drive to make it available at a specific path within your operating system.

  2. Refer to the path of the mounted drive when configuring NFS, GlusterFS, or hostPath.

-- yosefrow
Source: StackOverflow