Today we’re going to set up Dynamic Storage on our kubernetes cluster. This will allow pods on my cluster to ask for storage to be mounted. I’m planning on using NFS as the backing storage.
Create the share
Go into the synology GUI and create the share. Set it up the same way other things are. Namely no squashing, R/W access by local admins and admins, docker, and media for LDAP groups. ssh into the san and change the directory mode of the just created dir to 755.
Create the persistent dynamic volume manager
I find this hard to believe, but according to the documentation all I have to do to create an NFS dynamic volume handler is just helm install stable/nfs-client-provisioner --set nfs.server=$(getent hosts h2gt2g|awk '{print $1}') --set nfs.path=/volume1/k8s
Yes, it really was that easy. What was hard was trying to figure out how to use it. Even that was easy once I stopped overthinking it.
First nfs-pvc.yaml, the persistent volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs
spec:
accessModes:
- ReadWriteMany
storageClassName: "nfs-client"
resources:
requests:
storage: 1Mi
Next pod.yaml, a pod to use the persistent volume claim
# This mounts the nfs volume claim into /mnt and continuously
# overwrites /mnt/index.html with the time and hostname of the pod.
apiVersion: v1
kind: ReplicationController
metadata:
name: nfs-busybox
spec:
replicas: 2
selector:
name: nfs-busybox
template:
metadata:
labels:
name: nfs-busybox
spec:
containers:
- image: busybox
command:
- sh
- -c
- 'while true; do date > /mnt/index.html; hostname >> /mnt/index.html; sleep $(($RANDOM % 5 + 5)); done'
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
# name must match the volume name below
- name: nfs
mountPath: "/mnt"
volumes:
- name: nfs
persistentVolumeClaim:
claimName: nfs
And now we test
denebeim@frankiemouse:~/kubernetes/storage$ kubectl create -f nfs-pvc.yaml -f pod.yaml
persistentvolumeclaim/nfs created
replicationcontroller/nfs-busybox created
denebeim@frankiemouse:~/kubernetes/storage$ cat foo/
default-nfs-pvc-07001ca1-5d11-42e3-9316-33ca23e79d13/ #recycle/
denebeim@frankiemouse:~/kubernetes/storage$ cat foo/default-nfs-pvc-07001ca1-5d11-42e3-9316-33ca23e79d13/index.html
Tue Oct 29 04:43:46 UTC 2019
nfs-busybox-824rh
Written with StackEdit.
No comments:
Post a Comment