<p>I have a k8s cluster created using Kube-spray. The volume provisioning is supported using Rook. I was using persistent volumes till now.</p>

<p>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.</p>

<p>How can I accomplish this? How to use ephemeral volumes?</p>

<p>Already tried removing the PVs before performing the helm upgrade.</p>

AnjK
<p><code>helm upgrade</code> will try to keep as much of the existing infrastructure around as it can. If you already have a PersistentVolumeClaim named <code>myapp-pvc</code>, and you run <code>helm upgrade</code>, 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.</p>

<p>The blunt approach is to run <code>helm del --purge</code> the existing installation, wait for the PVCs to be fully cleaned up, and then <code>helm install</code> anew.</p>

<p>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 <a href="https://helm.sh/docs/chart_template_guide/#built-in-objects" rel="nofollow noreferrer">chart metadata</a> to provide this</p>

<pre><code>{{- define "myapp.pvc.name" -}}
{{ .Release.Name }}-{{ .Chart.Name }}-pvc
{{- if .Values.destroyPersistentState -}}
-{{ .Release.Revision }}
{{- end -}}
{{- end -}}
</code></pre>
