Retain Persistence Volume and use the PV for new Helm install

3/22/2019

In my Mongo Helm Chart, I am using PVC for Persistence volume. I am using the chart to install Mongo. When I delete the chart my PV gets deleted. So, I found something to patch it in.

kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'

After this my PV is not getting deleted just the status in Released

pvc-fc29a491-499a-11e9-a426-42010a800ff9   8Gi        RWO            Retain           Released      default/myapp-mongodb           standard                 3d

How can I bound this PV to my new helm chart installation so that my data should remain persistent even after deleting my Helm Chart?

-- Avinash Kumar
kubernetes
kubernetes-helm
kubernetes-pvc
mongodb
persistence

2 Answers

3/26/2019

I found one work around.I have created a PVC independent of helm chart and just using it in my deployment.yaml file.
If there is existing claim just use the existing one otherwise create a new Claim.

 {{- if .Values.persistence.enabled }}
      {{- if .Values.persistence.existingClaim }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim }}
      {{- else}}
        persistentVolumeClaim:
          claimName: {{ (include "mongodb.fullname" .) }}
      {{- end}}  
-- Avinash Kumar
Source: StackOverflow

3/22/2019
-- wrogrammer
Source: StackOverflow