Using Local Path Provisioner

Using Local Path Provisioner

Overview

Local Path Provisioner, provides a way for the Kubernetes users to utilize the local storage in each node. It supports multi-node setups. This tutorial will show you how to setup local-path-prvisioner on two node minikube cluster.

Prerequisites

  • Minikube version higher than v1.27.0
  • kubectl

Tutorial

  • Start a cluster with 2 nodes:
  1. $ minikube start -n 2
  • Enable storage-provisioner-rancher addon:
  1. $ minikube addons enable storage-provisioner-rancher
  • You should be able to see Pod in the local-path-storage namespace:
  1. $ kubectl get pods -n local-path-storage
  2. NAME READY STATUS RESTARTS AGE
  3. local-path-provisioner-7f58b4649-hcbk9 1/1 Running 0 38s
  • The local-path StorageClass should be marked as default:
  1. $ kubectl get sc
  2. NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
  3. local-path (default) rancher.io/local-path Delete WaitForFirstConsumer false 107s
  4. standard k8s.io/minikube-hostpath Delete Immediate false 4m27s
  • The following yaml creates PVC and Pod that creates file with content on second node (minikube-m02):
  1. ---
  2. apiVersion: v1
  3. kind: PersistentVolumeClaim
  4. metadata:
  5. name: test-pvc
  6. spec:
  7. accessModes:
  8. - ReadWriteOnce
  9. resources:
  10. requests:
  11. storage: 64Mi
  12. ---
  13. apiVersion: v1
  14. kind: Pod
  15. metadata:
  16. name: test-local-path
  17. spec:
  18. restartPolicy: OnFailure
  19. nodeSelector:
  20. "kubernetes.io/hostname": "minikube-m02"
  21. containers:
  22. - name: busybox
  23. image: busybox:stable
  24. command: ["sh", "-c", "echo 'local-path-provisioner' > /test/file1"]
  25. volumeMounts:
  26. - name: data
  27. mountPath: /test
  28. volumes:
  29. - name: data
  30. persistentVolumeClaim:
  31. claimName: test-pvc
  1. $ kubectl get pvc
  2. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  3. test-pvc Bound pvc-f07e253b-fea7-433a-b0ac-1bcea3f77076 64Mi RWO local-path 5m19s
  1. $ kubectl get pods -o wide
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. test-local-path 0/1 Completed 0 5m19s 10.244.1.5 minikube-m02 <none> <none>
  • On the second node we are able to see created file with content local-path-provisioner:
  1. $ minikube ssh -n minikube-m02 "cat /opt/local-path-provisioner/pvc-f07e253b-fea7-433a-b0ac-1bcea3f77076_default_test-pvc/file1"
  2. local-path-provisioner

Last modified October 4, 2022: Add tutorial of using local-path-provisioner (0fb290e39)