Configuring a VolumeSnapshot
VolumeSnapshot configurations can be classified into dynamically provisioned VolumeSnapshots and pre-provisioned VolumeSnapshots.
- A dynamically provisioned VolumeSnapshot is created by using VolumeSnapshot resources to dynamically obtain and create a snapshot from PVCs, without using existing snapshots.
- A pre-provisioned VolumeSnapshot requires the administrator to create the required snapshot on the storage device in advance and use the existing snapshot by creating a VolumeSnapshotContent. In addition, you can specify the associated VolumeSnapshotContent when creating a VolumeSnapshot.
1 - Dynamically Provisioning a VolumeSnapshot
This section describes how to dynamically provision a VolumeSnapshot using Huawei CSI.
Prerequisites
- The source PVC exists, and the backend where the PVC resides supports VolumeSnapshot creation.
Creating a Snapshot for a Volume
The following is an example of the VolumeSnapshot configuration file:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: mysnapshot
spec:
volumeSnapshotClassName: mysnapclass
source:
persistentVolumeClaimName: mypvc
You can modify the parameters according to
Table 1
.
Table 1 VolumeSnapshot parameters
Parameter | Description | Remarks |
|---|
metadata.name | User-defined name of a VolumeSnapshot object. | Take Kubernetes v1.22.1 as an example. The value can contain digits, lowercase letters, hyphens (-), and periods (.), and must start and end with a letter or digit. |
spec.volumeSnapshotClassName | Name of the VolumeSnapshotClass object. | -- |
spec.source.persistentVolumeClaimName | Name of the source PVC object. | Name of the source PVC of the snapshot |
Run the following command to create a VolumeSnapshot using the created VolumeSnapshot configuration file.
kubectl create -f mysnapshot.yaml
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 - Pre-provisioning a VolumeSnapshot
This section describes how to pre-provision a VolumeSnapshot using Huawei CSI.
Prerequisites
- A source VolumeSnapshot has been created on the Huawei storage device, and the created snapshot name can be obtained.
Creating a VolumeSnapshot Entity
The following is an example of the VolumeSnapshotContent file:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotContent
metadata:
name: mysnapshotcontent
spec:
deletionPolicy: Retain
driver: csi.huawei.com
volumeSnapshotRef:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
name: mysnapshot
namespace: default
source:
snapshotHandle: mybackend.1.snapshot_001
volumeSnapshotClassName: "mysnapclass"
You can modify the parameters according to
Table 1
.
Table 1 VolumeSnapshotContent parameters
Parameter | Description | Remarks |
|---|
metadata.name | User-defined name of a VolumeSnapshotContent object. | Take Kubernetes v1.22.1 as an example. The value can contain digits, lowercase letters, hyphens (-), and periods (.), and must start and end with a letter or digit. |
spec.deletionPolicy | Deletion policy. The following types are supported: - Delete: Resources are automatically reclaimed.
- Retain: Resources are manually reclaimed.
| - Delete: When a VolumeSnapshotContent is deleted, the snapshot resources on the storage are also deleted.
- Retain: When a VolumeSnapshotContent is deleted, the snapshot resources on the storage are not deleted.
|
spec.driver | Driver name. | Set this parameter to the driver name set during Huawei CSI installation. The value is the same as that of driverName in the values.yaml file. |
spec.volumeSnapshotRef | Information about the target VolumeSnapshot to be bound, including the VolumeSnapshot name and namespace. | -- |
spec.source.snapshotHandle | Unique identifier of a storage snapshot resource. This parameter is mandatory. The format is <backend-name>.<parent-id>.<snapshot-name>. | The value of this parameter consists of the following parts: - <backend-name>: indicates the backend name corresponding to the snapshot resource. You can run the oceanctl get backend command to obtain the configured backend information.
- <parent-id>: indicates the ID of the parent resource object of the snapshot resource on the storage device. You can view the ID on DeviceManager.
- <snapshot-name>: indicates the name of the snapshot resource on the storage device. You can view the name on DeviceManager.
NOTICE:The <snapshot-name> parameter can contain only digits, letters, and underscores (_). |
spec.volumeSnapshotClassName | Name of the VolumeSnapshotClass object. | -- |
Run the following command to create a VolumeSnapshotContent using the created VolumeSnapshotContent configuration file.
kubectl create -f mysnapshotcontent.yaml
Run the following command to view the information about the created VolumeSnapshot.
kubectl get volumesnapshotcontent
The following is an example of the command output.
NAME READYTOUSE RESTORESIZE DELETIONPOLICY DRIVER VOLUMESNAPSHOTCLASS VOLUMESNAPSHOT VOLUMESNAPSHOTNAMESPACE AGE
mysnapshotcontent true 0 Retain csi.huawei.com mysnapclass mysnapshot default 4s
Creating a Snapshot for a Volume
After a VolumeSnapshotContent is created in provisioned mode, you can create a VolumeSnapshot based on the VolumeSnapshotContent. The following is an example of the VolumeSnapshot configuration file:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: mysnapshot
namespace: default
spec:
volumeSnapshotClassName: mysnapclass
source:
volumeSnapshotContentName: mysnapshotcontent
You can modify the parameters according to
Table 2
.
Table 2 VolumeSnapshot parameters
Parameter | Description | Remarks |
|---|
metadata.name | User-defined name of a VolumeSnapshot object. | Take Kubernetes v1.22.1 as an example. The value can contain digits, lowercase letters, hyphens (-), and periods (.), and must start and end with a letter or digit. The value must be the same as the name of the VolumeSnapshot specified by VolumeSnapshotContent. |
metadata.namespace | Namespace to which the VolumeSnapshot belongs. | The value must be the same as the namespace of the VolumeSnapshot specified by VolumeSnapshotContent. |
spec.volumeSnapshotClassName | Name of the VolumeSnapshotClass object. | -- |
spec.source.volumeSnapshotContentName | Name of the source VolumeSnapshotContent object. | Name of the source VolumeSnapshotContent of the snapshot. |
Run the following command to create a VolumeSnapshot using the created VolumeSnapshot configuration file.
kubectl create -f mysnapshot.yaml
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 mysnapshotcontent 0 mysnapclass mysnapshotcontent 2m39s 8s