<p>I'm trying to get my head around Persistent Volumes &amp; Persistent Volume Claims and how it should be done in Helm...</p>

<p>The <strong>TLDR</strong> version of the question is: How do I create a PVC in helm that I can attach future releases (whether upgrades or brand new installs) to? </p>

<p><strong>My current understanding:</strong></p>

<p>PV is an interface to a piece of physical storage.
PVC is how a pod claims the existence of a PV for its own use. When the pod is deleted, the PVC is also deleted, but the PV is maintained - and is therefore persisted. But then how I do use it again?</p>

<p>I know it is possible to dynamically provision PVs. Like with Google Cloud as an example if you create <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes" rel="noreferrer"><strong>ONLY</strong> a PVC</a>, it will automatically create a PV for you.</p>

<p>Now this is the part I'm stuck on...</p>

<p>I've created a helm chart that explicitly creates the PVC &amp; thus has a dynamically created PV as part of a release. I then later <em>delete</em> the release, which will then also remove the PVC. The cloud provider will <em>maintain</em> the PV. On a subsequent install of the same chart with a new release... How do I reuse the old PV? Is there a way to actually do that?</p>

<p>I did find <a href="https://stackoverflow.com/questions/49344501/how-can-you-reuse-dynamically-provisioned-persistentvolumes-with-helm-on-gke">this question</a> which kind of answers it... However, it implies that you need to pre-create PVs for each PVC you're going to need, and the whole point of the replicas &amp; auto-scaling is that all of those should be generated on demand.</p>

<p>The use case is - as always - for test/dev environments where I want my data to be persisted, but I don't always want the servers running.</p>

<p>Thank you in advance! My brain's hurting a bit cause I just can't figure it out... >.&lt;</p>

<p>It will be a headache indeed. </p>

<p>Let's start with how you should do it to achieve scalable deployments with RWO storages that are attached to your singular pods when they are brought up. This is where volumeClaimTemplates come into play. You can have PVC created dynamicaly as your Deployment scales. This however suits well situation when your pod needs storage that is attached to a pod, but not really needed any longer when pod goes away (volume can be reused following reclaim policy.</p>

<p>If you need the data like this reatached when pod fails, you should think of StatefulSets which solve that part at least.</p>

<p>Now, if you precreate PVC explicitly, you have more control over what happens, but dynamic scalability will have problems with this for RWO. This and manual PV management as in the response you linked can actually achieve volume reuse, and it's the only mechanism that would allow it that I can think of.</p>

<p>After you hit a wall like this it's time to think about alternatives. For example, why not use a StatefulSet that will give you storage retention in running cluster and instead of deleting the chart, set all it's replicas to 0, retaining non-compute resources in place but scaling it down to nothing. Then when you scale up a still bound PVC should get reattached to rescaled pods.</p>
