Home Explore Blog CI



kubernetes

2nd chunk of `content/en/docs/tasks/administer-cluster/change-pv-reclaim-policy.md`
3556b55664c210f897b5500dc4968d56cb78b4fc90b5b78c0000000100000c27
1. List the PersistentVolumes in your cluster:

   ```shell
   kubectl get pv
   ```

   The output is similar to this:

   ```none
   NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM             STORAGECLASS     REASON    AGE
   pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Delete          Bound     default/claim1    manual                     10s
   pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Delete          Bound     default/claim2    manual                     6s
   pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Delete          Bound     default/claim3    manual                     3s
   ```

   This list also includes the name of the claims that are bound to each volume
   for easier identification of dynamically provisioned volumes.

1. Choose one of your PersistentVolumes and change its reclaim policy:

   ```shell
   kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
   ```

   where `<your-pv-name>` is the name of your chosen PersistentVolume.

   {{< note >}}
   On Windows, you must _double_ quote any JSONPath template that contains spaces (not single
   quote as shown above for bash). This in turn means that you must use a single quote or escaped
   double quote around any literals in the template. For example:

   ```cmd
   kubectl patch pv <your-pv-name> -p "{\"spec\":{\"persistentVolumeReclaimPolicy\":\"Retain\"}}"
   ```
   {{< /note >}}

1. Verify that your chosen PersistentVolume has the right policy:

   ```shell
   kubectl get pv
   ```

   The output is similar to this:

   ```none
   NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM             STORAGECLASS     REASON    AGE
   pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Delete          Bound     default/claim1    manual                     40s
   pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Delete          Bound     default/claim2    manual                     36s
   pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94   4Gi        RWO           Retain          Bound     default/claim3    manual                     33s
   ```

   In the preceding output, you can see that the volume bound to claim
   `default/claim3` has reclaim policy `Retain`. It will not be automatically
   deleted when a user deletes claim `default/claim3`.

## {{% heading "whatsnext" %}}

* Learn more about [PersistentVolumes](/docs/concepts/storage/persistent-volumes/).
* Learn more about [PersistentVolumeClaims](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims).

### References {#reference}

* {{< api-reference page="config-and-storage-resources/persistent-volume-v1" >}}
  * Pay attention to the `.spec.persistentVolumeReclaimPolicy`
    [field](/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-v1/#PersistentVolumeSpec)
    of PersistentVolume.
* {{< api-reference page="config-and-storage-resources/persistent-volume-claim-v1" >}}


Title: Steps to Change the Reclaim Policy of a PersistentVolume
Summary
This section details the steps to change the reclaim policy of a PersistentVolume in Kubernetes. It involves listing PVs using `kubectl get pv`, selecting a PV, and patching its reclaim policy to "Retain" using `kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'`. A note is included for Windows users regarding double-quoting JSONPath templates. Finally, the section instructs to verify the change using `kubectl get pv` and provides references to PersistentVolumes and PersistentVolumeClaims documentation.