<p>I have a question, what is the reason to use the <strong>Retain</strong> reclaim policy of a PersistentVolume for <strong>StatefulSet</strong>. Is StatefulSet not secure enough ?</p>
<p>As far as I know, when a StatefulSet-managed replica disappears, either because the StatefulSet is reducing its replica count, or because its StatefulSet is deleted, the PVC and its backing volume remains and must be manually deleted.</p>

Xavier123
<p>You can't directly set the PersistentVolume <code>persistentVolumeReclaimPolicy:</code> from a StatefulSet, and you probably don't want to change it from the default.</p>
<p>The <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming" rel="nofollow noreferrer">reclaim policy</a> tells Kubernetes what to do with the actual storage behind a <a href="https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-v1/" rel="nofollow noreferrer">PersistentVolume</a> when it is deleted.  If you set <code>persistentVolumeReclaimPolicy: Retain</code> then whatever actual storage was in use, such as an AWS EBS volume, will simply be left behind and you'll be responsible for cleaning it up.  This is very occasionally useful if you need to create a PersistentVolume that refers to some existing external storage, but it's not an option you should usually need.</p>
<p>A <a href="https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-claim-v1/" rel="nofollow noreferrer">PersistentVolumeClaim</a> doesn't have this option.  It is an object that tells Kubernetes that you'd like some specific storage to exist, but not where that storage actually is or what its physical properties are.  A StatefulSet provides a template for a PersistentVolumeClaim, not the underlying PersistentVolumes, and so you can't set a reclaim policy on a StatefulSet-derived volume.</p>
<p>An important property of StatefulSet-associated volumes is that each replica has its own volume, via its own PVC.  That means the cluster dynamically creates PVCs, and the cluster's persistent volume provisioner dynamically allocates external storage and creates PVs.  In turn, this means you almost certainly don't want to set <code>persistentVolumeReclaimPolicy: Retain</code> on these volumes: when you do <code>kubectl delete pvc</code> to clean up the storage, that option would leave the dynamically-created external storage behind, and you'd need to find that and clean it up by hand.  The default <code>Delete</code> value will delete the external storage when the PersistentVolume is deleted, which is most likely what you want to happen.</p>
