Reference:
- https://kubernetes.io/docs/concepts/storage/persistent-volumes
- https://kubernetes.io/docs/concepts/storage/volumes/#local
- https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner/tree/master/examples
Create Kind cluster
kind create cluster --name localvoltest --kubeconfig ./localvoltest.conf
If you open a new shell set KUBECONFIG, eg. export KUBECONFIG=$(pwd)/localvoltest.conf
Create persistent volume config then load it. Configure the path you want to use for the volume. I used /var/tmp
. See manual-pv.yaml
kubectl apply -f manual-pv.yaml
Note: the hostname for affinity is matching what's in kind or it did not work for me
Create persistent volume claim config then apply it to the cluster. See simple-pvc.yaml
kubectl apply -f simple-pvc.yml
Start an pod which writes to a file in the persistent volume. To show more of how not to do things I'm starting a multiple replicas in my example which all write to the same file w/o properly dealing with lock files :) See #local-writer.yaml. Load with
kubectl apply -f local-writer.yaml
Start another pod to read from the file in the same volume. See local-reader.yaml
kubectl apply -f local-reader.yaml
Monitor the data being written to the local file via the local-reader pod logs:
kubectl logs local-test-reader-TEMP_INSTANCE_NAME --tail=10 --follow
Cleanup the volumes and pods
kubectl delete deploy local-writer
kubectl delete deploy local-reader
kubectl delete pvc example-local-claim
kubectl delete pvc example-local-pv
Delete the kind cluster: kind delete cluster --name localvoltest
TODO: