1 - Querying a VolumeSnapshot

Viewing a VolumeSnapshotClass

  1. Run the following command to view the information about the created VolumeSnapshotClass.

    kubectl get volumesnapshotclass
    

    The following is an example of the command output.

    NAME          DRIVER           DELETIONPOLICY   AGE
    mysnapclass   csi.huawei.com   Delete           25s
    

Querying a Volume Snapshot

  1. Run the following command to view the information about the created VolumeSnapshot.

    kubectl get volumesnapshot
    

    The following is an example of the command output.

    NAME         READYTOUSE   SOURCEPVC   SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS   SNAPSHOTCONTENT                                    CREATIONTIME   AGE
    mysnapshot   true         mypvc                               100Gi         mysnapclass     snapcontent-1009af0a-24c2-4435-861c-516224503f2d   <invalid>      78s
    

2 - Creating a PV Using a VolumeSnapshot

Prerequisites

  • Compatibility and Features lists storage that support PVC creation using a VolumeSnapshot. You need to search by the storage type and service type.
  • Kubernetes Feature Matrix lists the Kubernetes versions that support PVC creation using a VolumeSnapshot.
  • A VolumeSnapshot exists, and the backend where the VolumeSnapshot resides supports cloning.

When creating a PVC, you need to specify a VolumeSnapshot as the data source. The following is an example of creating a PVC using a VolumeSnapshot. In this example, mysnapshot is used as the data source and a PVC named myrestore is created.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myrestore
spec:
  storageClassName: mysc
  dataSource:
    name: mysnapshot
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Gi

  • The specified storageClassName must be the same as the StorageClass of the snapshot source volume in dataSource.
  • The capacity of the clone volume must be greater than or equal to that of the snapshot. Equal capacity is recommended.

Procedure

  1. Run the following command to create a PVC based on the configuration file for creating a volume using a snapshot.

    kubectl create -f myrestore.yaml
    

3 - Deleting a VolumeSnapshot

Deleting a VolumeSnapshot

Perform this operation when the volume snapshot is no longer required.

Procedure

  1. Run the following command to view the information about the created VolumeSnapshot.

    kubectl get volumesnapshot
    

    The following is an example of the command output.

    NAME         READYTOUSE   SOURCEPVC   SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS   SNAPSHOTCONTENT                                    CREATIONTIME   AGE
    mysnapshot   true         mypvc                               100Gi         mysnapclass     snapcontent-1009af0a-24c2-4435-861c-516224503f2d   <invalid>      78s
    
  2. Run the following command to delete the VolumeSnapshot:

    kubectl delete volumesnapshot mysnapshot 
    

    If the following information is displayed, the deletion is successful:

    volumesnapshot.snapshot.storage.k8s.io "mysnapshot" deleted
    

Deleting a VolumeSnapshotClass

Perform this operation when the VolumeSnapshotClass is not bound to any VolumeSnapshot and the VolumeSnapshotClass is no longer required.

Procedure

  1. Run the following command to view the VolumeSnapshotClass:

    kubectl get vsclass
    

    The following is an example of the command output.

    NAME          DRIVER           DELETIONPOLICY   AGE
    mysnapclass   csi.huawei.com   Delete           25s
    
  2. Run the following command to delete the StorageClass:

    kubectl delete vsclass mysnapclass
    

    If the following information is displayed, the deletion is successful:

    volumesnapshotclass.snapshot.storage.k8s.io "mysnapclass" deleted