This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Creating a VolumeSnapshot

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

1 - Checking Information About Volume Snapshot-dependent Components

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.

2 - Configuring a VolumeSnapshotClass

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:

  • If api-versions in your environment supports v1, use the following example:

    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshotClass
    metadata:
      name: mysnapclass
    driver: csi.huawei.com
    deletionPolicy: Delete
    
  • If api-versions in your environment supports v1beta1, use the following example:

    apiVersion: snapshot.storage.k8s.io/v1beta1
    kind: VolumeSnapshotClass
    metadata:
      name: mysnapclass
    driver: csi.huawei.com
    deletionPolicy: Delete
    
  • If api-versions in your environment supports both v1 and v1beta1, v1 is recommended.

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

Parameter

Description

Remarks

metadata.name

User-defined name of a VolumeSnapshotClass 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.

driver

driver identifier. This parameter is mandatory.

Set this parameter to the driver name set during Huawei CSI installation. The default driver name is csi.huawei.com.

deletionPolicy

Snapshot deletion policy. This parameter is mandatory. The value can be:

  • Delete
  • Retain
  • If the deletion policy is Delete, the snapshot on the storage device will be deleted together with the VolumeSnapshotContent object.
  • If the deletion policy is Retain, the snapshot and VolumeSnapshotContent object on the storage device will be retained.

Prerequisites

Huawei CSI supports snapshots, and the volume snapshot component CRD on which its running depends has been installed. For details about the CRD, see Checking Volume Snapshot-Dependent Components. For details about the Kubernetes versions that support VolumeSnapshot creation, see Table 1.

Procedure

  1. Run the following command to create a VolumeSnapshotClass using the created VolumeSnapshotClass configuration file.

    kubectl create -f mysnapclass.yaml
    
  2. 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
    

3 - Configuring a VolumeSnapshot

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:

  • If api-versions in your environment supports v1, use the following example:

    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
      name: mysnapshot
    spec:
      volumeSnapshotClassName: mysnapclass
      source:
        persistentVolumeClaimName: mypvc
    
  • If api-versions in your environment supports v1beta1, use the following example:

    apiVersion: snapshot.storage.k8s.io/v1beta1
    kind: VolumeSnapshot
    metadata:
      name: mysnapshot
    spec:
      volumeSnapshotClassName: mysnapclass
      source:
        persistentVolumeClaimName: mypvc
    
  • The api-versions information in the VolumeSnapshot must be the same as the version used for creating the VolumeSnapshotClass.

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

Prerequisites

  • The source PVC exists, and the backend where the PVC resides supports VolumeSnapshot creation. For details about the storage devices that support VolumeSnapshot creation, see Table 2 and Table 2. For details about the Kubernetes versions that support VolumeSnapshot creation, see Table 1.
  • The volume snapshot component CRD on which the running of Huawei CSI depends has been installed. For details, see Checking Volume Snapshot-Dependent Components.
  • A VolumeSnapshotClass that uses Huawei CSI exists in the system.

Procedure

  1. Run the following command to create a VolumeSnapshot using the created VolumeSnapshot configuration file.

    kubectl create -f mysnapshot.yaml
    
  2. 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