// Module included in the following assembly:
//
// assembly-cluster-recovery-volume.adoc

[id="namespace-deletion_{context}"]
= Recovery from namespace deletion

Recovery from namespace deletion is possible because of the relationship between persistent volumes and namespaces.
A `PersistentVolume` (PV) is a storage resource that lives outside of a namespace.
A PV is mounted into a Kafka pod using a `PersistentVolumeClaim` (PVC), which lives inside a namespace.

The reclaim policy for a PV tells a cluster how to act when a namespace is deleted.
If the reclaim policy is set as:

*  _Delete_ (default), PVs are deleted when PVCs are deleted within a namespace
* _Retain_, PVs are not deleted when a namespace is deleted

To ensure that you can recover from a PV if a namespace is deleted unintentionally, the policy must be reset from _Delete_ to _Retain_ in the PV specification using the `persistentVolumeReclaimPolicy` property:

[source,shell,subs="+quotes,attributes"]
----
apiVersion: v1
kind: PersistentVolume
# ...
spec:
  # ...
  *persistentVolumeReclaimPolicy: Retain*
----

Alternatively, PVs can inherit the reclaim policy of an associated storage class.
Storage classes are used for dynamic volume allocation.

By configuring the `reclaimPolicy` property for the storage class, PVs that use the storage class are created with the appropriate reclaim policy.
The storage class is configured for the PV using the `storageClassName` property.

[source,shell,subs="+quotes,attributes"]
----
apiVersion: v1
kind: StorageClass
metadata:
  *name: gp2-retain*
parameters:
  # ...
# ...
*reclaimPolicy: Retain*
----

[source,shell,subs="+quotes,attributes"]
----
apiVersion: v1
kind: PersistentVolume
# ...
spec:
  # ...
  *storageClassName: gp2-retain*
----

NOTE: If you are using _Retain_ as the reclaim policy, but you want to delete an entire cluster, you need to delete the PVs manually.
Otherwise they will not be deleted, and may cause unnecessary expenditure on resources.
