<p><strong>TL;DR</strong></p>

<p>My pods mounted Azure file shares are (inconsistently) being deleted by either Kubernetes / Helm when deleting a deployment.</p>

<p><strong>Explanation</strong></p>

<p>I've recently transitioned to using Helm for deploying Kubernetes objects on my Azure Kubernetes Cluster via the DevOps release pipeline.</p>

<p>I've started to see some unexpected behaviour in relation to the Azure File Shares that I mount to my Pods (as Persistent Volumes with associated Persistent Volume Claims and a Storage Class) as part of the deployment.</p>

<p>Whilst I've been finalising my deployment, I've been pushing out the deployment via the Azure Devops release pipeline using the built in Helm tasks, which have been working fine. When I've wanted to fix / improve the process I've then either manually deleted the objects on the Kubernetes Dashboard (UI), or used Powershell (command line) to delete the deployment.</p>

<p>For example:</p>

<pre><code>helm delete myapp-prod-73
helm del --purge myapp-prod-73
</code></pre>

<p>Not every time, but more frequently, I'm seeing the underlying Azure File Shares also being deleted as I'm working through this process. There's very little around the web on this, but I've also seen an article outlining similar issues over at: <a href="https://winterdom.com/2018/07/26/kubernetes-azureFile-dynamic-volumes-deleting" rel="nofollow noreferrer">https://winterdom.com/2018/07/26/kubernetes-azureFile-dynamic-volumes-deleting</a>.</p>

<p>Has anyone in the community come across this issue?</p>

<p><strong>Credit goes to</strong> <a href="https://twitter.com/tomasrestrepo" rel="nofollow noreferrer">https://twitter.com/tomasrestrepo</a> here on pointing me in the right direction (the author of the article I mentioned above).</p>

<p>The behaviour here was a consequence of having the Reclaim Policy on the Storage Class &amp; Persistent Volume set to "Delete".  When switching over to Helm, I began following their commands to Delete / Purge the releases as I was testing.  What I didn't realise, was that deleting the release would also mean that Helm / K8s would also reach out and delete the underlying Volume (in this case an Azure Fileshare).  This is documented over at: <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#delete" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/#delete</a></p>

<p>I'll leave this Q &amp; A here for anyone else that misses this subtly with the way in which the Storage Classes, Persistent Volumes (PVs) &amp; underlying storage operates under K8s / Helm.</p>

<p><strong>Note</strong>: I think this issue was made slightly more obscure by the fact I was manually creating the Azure Fileshare (through the Azure Portal) and trying to mount that as a static volume (as per <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-volume" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/aks/azure-files-volume</a>) within my Helm Chart, but that the underlying volume wasn't immediately being deleted when the release was deleted (sometimes an hour later?).</p>
