Home Explore Blog CI



kubernetes

1st chunk of `content/en/docs/tasks/administer-cluster/change-pv-reclaim-policy.md`
80ff131444cf378f56a413f286f2b616b7c9924e336ceb30000000010000086a
---
title: Change the Reclaim Policy of a PersistentVolume
content_type: task
weight: 100
---

<!-- overview -->
This page shows how to change the reclaim policy of a Kubernetes
PersistentVolume.

## {{% heading "prerequisites" %}}

{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}

<!-- steps -->

## Why change reclaim policy of a PersistentVolume

PersistentVolumes can have various reclaim policies, including "Retain",
"Recycle", and "Delete". For dynamically provisioned PersistentVolumes,
the default reclaim policy is "Delete". This means that a dynamically provisioned
volume is automatically deleted when a user deletes the corresponding
PersistentVolumeClaim. This automatic behavior might be inappropriate if the volume
contains precious data. In that case, it is more appropriate to use the "Retain"
policy. With the "Retain" policy, if a user deletes a PersistentVolumeClaim,
the corresponding PersistentVolume will not be deleted. Instead, it is moved to the
Released phase, where all of its data can be manually recovered.

## Changing the reclaim policy of a PersistentVolume

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"}}'

Title: Changing the Reclaim Policy of a PersistentVolume in Kubernetes
Summary
This document explains how to modify the reclaim policy of a PersistentVolume (PV) in Kubernetes. The default reclaim policy for dynamically provisioned PVs is "Delete", which automatically deletes the volume when the corresponding PersistentVolumeClaim (PVC) is deleted. For PVs containing important data, the "Retain" policy is recommended, which prevents automatic deletion and moves the PV to the Released phase for manual data recovery. The guide provides steps to list PVs and use `kubectl patch` to change the reclaim policy to "Retain".