Adding Database to raspberry pi kubernetes cluster

4/21/2019

I'm fairly new to k8s, so forgive me if I misuse k8s terminology. I'm hoping someone could point me in the right direction and advise the best way to do this.

I have a k8s cluster running on a group of raspberry pis. I want to add a database volume accessible by all workers. I plan to use a usb external drive to store the database content.

Do I want to mount the external drive to the master node?

How is the external drive declared as a k8s resource?

Once configured, how is this external drive accessible by pods in other k8s nodes?

After reading through k8s Volumes page, it sounds like I might be looking for a Volume of "local" type. If I mount a local volume to the master node, will I be able to run a postgres container in a worker node and access the volume mounted on the master node?

-- user9270368
database
kubernetes
raspberry-pi

2 Answers

4/22/2019

If I mount a local volume to the master node, will I be able to run a postgres container in a worker node and access the volume mounted on the master node?

No. You will need to run something to make your volume accessible to other nodes. There are tons of filesystems for that purpose (Ceph, Lustre, even NFS, etc.) And there are starting to be Kubernetes native ones too (i.e. Rook.)

-- BraveNewCurrency
Source: StackOverflow

4/22/2019

Easiest thing is to set up NFS server on master node, export your USB drive over NFS and then mount it as Persistent Volume in pod. For this you need first to create PersistentVolume:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: master-node-ip
    path: /mnt/nfsserver

And then create PersistentVolumeClaim of the same size:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi

After that you can mount this PVC on all needed pods:

    volumeMounts:
    - name: nfs
      mountPath: "/usr/share/nginx/html"
  volumes:
  - name: nfs
    persistentVolumeClaim:
      claimName: nfs
-- Vasily Angapov
Source: StackOverflow