This is the multi-page printable view of this section. Click here to print.
Advanced Services
1 - Snapshot Management
In Kubernetes, a VolumeSnapshot is a snapshot of a volume on a storage system. The VolumeSnapshot capability provides Kubernetes users with a standard way to replicate the content of a volume at a specified point in time without creating a volume. For example, this function enables database administrators to back up the database before making changes such as editing or deleting.
This section describes how to create a VolumeSnapshot using Huawei CSI. To create a VolumeSnapshot, perform the following steps:
- Checking information about volume snapshot-dependent components
- Configuring a VolumeSnapshotClass
- Configuring a VolumeSnapshot
Prerequisites
- Compatibility and Features lists storage that support VolumeSnapshot creation. You need to search by the storage type and service type.
- For details about the Kubernetes versions that support VolumeSnapshot creation, see Table 1 .
- If you need to use volume snapshots and features associated with volume snapshots in the container environment, perform the operations in Checking Volume Snapshot-Dependent Components to check whether volume snapshot-dependent components have been deployed in your environment and check the api-versions information about volume snapshots.
- The source PVC exists, and the backend where the PVC resides supports VolumeSnapshot creation.
1.1 - Configuring a Volume Snapshot
Creating a Volume Snapshot Class
VolumeSnapshotClass provides a way to describe the “classes” of storage when provisioning a VolumeSnapshot. Each VolumeSnapshotClass contains the driver, deletionPolicy, and parameters fields, which are used when a VolumeSnapshot belonging to the class needs to be dynamically provisioned.
The name of a VolumeSnapshotClass object is significant, and is how users can request a particular class. Administrators set the name and other parameters of a class when first creating VolumeSnapshotClass objects, and the objects cannot be updated once they are created.
The following is an example of a VolumeSnapshotClass used by Huawei CSI:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: mysnapclass
driver: csi.huawei.com
deletionPolicy: Delete
You can modify the parameters according to Table 1 . Currently, Huawei CSI does not support user-defined parameters (parameters) in a VolumeSnapshotClass. Therefore, you are advised to create a VolumeSnapshotClass for all snapshots.
Table 1 VolumeSnapshotClass parameters
Procedure
Run the following command to create a VolumeSnapshotClass using the created VolumeSnapshotClass configuration file.
kubectl create -f mysnapclass.yamlRun the following command to view the information about the created VolumeSnapshotClass.
kubectl get volumesnapshotclassThe following is an example of the command output.
NAME DRIVER DELETIONPOLICY AGE mysnapclass csi.huawei.com Delete 25s
Creating a Snapshot for a Volume
VolumeSnapshot can be provisioned in two ways: pre-provisioning and dynamic provisioning . Currently, Huawei CSI supports only dynamic provisioning. This section describes how to dynamically provision a VolumeSnapshot using Huawei CSI. 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 2 .
Table 2 VolumeSnapshot parameters
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. | ||
Procedure
Run the following command to create a VolumeSnapshot using the created VolumeSnapshot configuration file.
kubectl create -f mysnapshot.yamlRun the following command to view the information about the created VolumeSnapshot.
kubectl get volumesnapshotThe 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
1.2 - Managing Volume Snapshots
1.2.1 - Querying a VolumeSnapshot
Viewing a VolumeSnapshotClass
Run the following command to view the information about the created VolumeSnapshotClass.
kubectl get volumesnapshotclassThe following is an example of the command output.
NAME DRIVER DELETIONPOLICY AGE mysnapclass csi.huawei.com Delete 25s
Querying a Volume Snapshot
Run the following command to view the information about the created VolumeSnapshot.
kubectl get volumesnapshotThe 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
1.2.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
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
1.2.3 - Deleting a VolumeSnapshot
Deleting a VolumeSnapshot
Perform this operation when the volume snapshot is no longer required.
Procedure
Run the following command to view the information about the created VolumeSnapshot.
kubectl get volumesnapshotThe 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> 78sRun the following command to delete the VolumeSnapshot:
kubectl delete volumesnapshot mysnapshotIf 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
Run the following command to view the VolumeSnapshotClass:
kubectl get vsclassThe following is an example of the command output.
NAME DRIVER DELETIONPOLICY AGE mysnapclass csi.huawei.com Delete 25sRun the following command to delete the StorageClass:
kubectl delete vsclass mysnapclassIf the following information is displayed, the deletion is successful:
volumesnapshotclass.snapshot.storage.k8s.io "mysnapclass" deleted