3

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
avinashjha
  • 590
  • 4
  • 18

3 Answers3

1

It's still not resolved issue by Helm.

The 'hack' to deal with it, you can find here:

https://groups.google.com/forum/#!topic/kubernetes-sig-apps/sLL2pCJ5Ab8

wrogrammer
  • 119
  • 8
0

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}}  
avinashjha
  • 590
  • 4
  • 18
  • there will be potential problem when you try to `helm upgrade install`, if the pvc is not installed by helm. – Lei Yang Aug 17 '20 at 02:46
  • 1
    @LeiYang I have been using the existing PVC for a while now and haven't found any issue yet.Can you help me what is the issue that might come ? – avinashjha Aug 18 '20 at 09:03
0

The existing PV will not be able to be bound to the new PVC. However, the disk that your PV (pvc-fc29a491-499a-11e9-a426-42010a800ff9) references can be bound to your PVC. The configuration of your new PV will depend slightly on what cloud provider/bare metal host you are using. I followed this to come to the example shown below. This example shows how to do it with a Google Cloud GCE persistent disk. The order matters here; make sure you create the PV (that references your existing persistent disk) before creating your PVC.

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: myPV
spec:
  capacity:
    storage: 8Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: myPdDiskName
    fsType: ext4
  storageClassName: standard
  claimRef:
    name: myPvcName
    namespace: myNameSpace

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myPvcName
  namespace: myNameSpace
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
J.D.
  • 51
  • 4