How do I connect a helm package to a PersistentStorage volume?

6/18/2020

I've seen this question come up often, and I've yet to find a clean, generic solution. I'm just learning Kubernetes so maybe there's something basic I'm missing. But here's what I've done:

  1. install docker-desktop with kubernetes
  2. manually create a persistent-storage volume using a yaml file (shown below)
  3. helm install redis dandydev/redis-ha

Or you can use any other helm chart, be it elasticsearch, postgres, you name it. I always get pod has unbound immediate PersistentVolumeClaims.

Also when I run: kubectl get storageclasses.storage.k8s.io I do have (default) storage:

NAME                 PROVISIONER          AGE
hostpath (default)   docker.io/hostpath   3h8m

Can anyone please help me fix this issue in a generic way? So that I can actually install helm charts and have them automatically connect to a persistent storage volume?

My volume.yaml:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: redis-volume
  labels:
    type: local
    app: redis
spec:
  storageClassName: ""
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/redis"
-- Cosmin Atanasiu
docker-desktop
kubernetes
kubernetes-helm
persistent-storage
redis

1 Answer

6/18/2020

Ok so I looked more online among the various custom solutions, and one did work: https://github.com/helm/charts/issues/12521#issuecomment-477834805

In addition this answer provides more details into how to enable dynamic provisioning locally: https://stackoverflow.com/questions/52668938/pod-has-unbound-persistentvolumeclaims

Basically (in addition to having the volume created above) I need to manually:

  1. create a storage class, via storage-class.yaml
  2. add that storage class to helm in 'values.yaml'
# storage-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: data-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

In addition, some charts running locally need you to customize their config, under <your-helm>/charts/<chart-name>/<file-to-config.yaml>, or via --set <var>=valuesince, most helm charts want you to use more nodes, and running locally you might only have a single node.

Another option is to use helm install --set replicas=1 ... and some charts will work well with this.

Hope this helps someone out there.

-- Cosmin Atanasiu
Source: StackOverflow