I have a k8s cluster created using Kube-spray. The volume provisioning is supported using Rook. I was using persistent volumes till now.
The application is deployed using the helm chart. The helm release is upgraded multiple times for the test-purposes. I want the pods to use new volume each time I upgrade the chart. I don't want the pod to use the old data after helm upgrade.
How can I accomplish this? How to use ephemeral volumes?
Already tried removing the PVs before performing the helm upgrade.
One trick that we could try for temporary volume is:
helm upgrade
.helm upgrade
will try to keep as much of the existing infrastructure around as it can. If you already have a PersistentVolumeClaim named myapp-pvc
, and you run helm upgrade
, it will notice that PVC already exists, and leave it intact. I think this happens at the Helm layer, but even if Helm uploaded an identical PVC description to Kubernetes, it would still result in no change.
The blunt approach is to run helm del --purge
the existing installation, wait for the PVCs to be fully cleaned up, and then helm install
anew.
Another possible approach is to encode some unique or random value in the PVC name. The trick is that you need the same value to be used across all uses of it within the same chart installation, but then to be different if the chart is upgraded. You can use a combination of the chart metadata to provide this
{{- define "myapp.pvc.name" -}}
{{ .Release.Name }}-{{ .Chart.Name }}-pvc
{{- if .Values.destroyPersistentState -}}
-{{ .Release.Revision }}
{{- end -}}
{{- end -}}