Deleting a volume snapshot
To clean up unneeded snapshots and free storage resources, delete volume snapshots by setting a deletion policy that controls whether the underlying content is retained or removed.
-
Specify the deletion policy that you require in the
VolumeSnapshotClassobject, as shown in the following example:Example volumesnapshotclass.yaml fileapiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotClass metadata: name: csi-hostpath-snap driver: hostpath.csi.k8s.io deletionPolicy: Delete # ...When deleting the volume snapshot, if
deletionPolicyis set toDelete, the underlying snapshot is deleted along with theVolumeSnapshotContentobject. If theRetainvalue is set, both the underlying snapshot andVolumeSnapshotContentobject remain.If the
Retainvalue is set and theVolumeSnapshotobject is deleted without deleting the correspondingVolumeSnapshotContentobject, the content remains. The snapshot itself is also retained in the storage back end. -
Delete the volume snapshot by entering the following command:
$ oc delete volumesnapshot <volumesnapshot_name>Replace
<volumesnapshot_name>with the name of the volume snapshot you want to delete.Example outputvolumesnapshot.snapshot.storage.k8s.io "mysnapshot" deleted -
If the deletion policy is set to
Retain, delete the volume snapshot content by entering the following command:$ oc delete volumesnapshotcontent <volumesnapshotcontent_name>Replace
<volumesnapshotcontent_name>with the content you want to delete. -
Optional: If the
VolumeSnapshotobject is not successfully deleted, enter the following command to remove any finalizers for the leftover resource so that the delete operation can continue:Only remove the finalizers if you are confident that there are no existing references from either persistent volume claims or volume snapshot contents to the
VolumeSnapshotobject. Even with the--forceoption, the delete operation does not delete snapshot objects until all finalizers are removed.$ oc patch -n $PROJECT volumesnapshot/$NAME --type=merge -p '{"metadata": {"finalizers":null}}'Example outputvolumesnapshotclass.snapshot.storage.k8s.io "csi-ocs-rbd-snapclass" deletedThe finalizers are removed and the volume snapshot is deleted.