<p>I am looking for a way to delete PersistentVolumeClaims assigned to pods of a StatefulSet automatically when I scale down the number of instances. Is there a way to do this within k8s? I haven't found anything in the docs, yet.</p>

<p>I suspect that a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#lifecycle-v1-core" rel="nofollow noreferrer"><code>preStop</code> Lifecycle Handler</a> could submit a <code>Job</code> to clean up the PVC, assuming the Pod's <code>ServiceAccount</code> had the <code>Role</code> to do so. Unfortunately, the Lifecycle Handler docs say that the <code>exec</code> blocks the Pod deletion, so that's why whatever happened would need to be asynchronous from the Pod's perspective.</p>

<p>Another approach might be to unconditionally scan the cluster or namespace with a <code>CronJob</code> and delete unassigned PVCs, or those that match a certain selector.</p>

<p>But I don't think there is any <em>inherent</em> ability to do that, given that (at least in my own usage) it's reasonable to scale a <code>StatefulSet</code> up and down, and when scaling it back up then one would actually desire that the <code>Pod</code> regain its identity in the <code>StatefulSet</code>, which typically includes any persisted data.</p>
