Skip to main content
Snapshots of the permanent volumes

Snapshots of the permanent volumes

Snapshots of permanent volumes (VolumeSnapshots) are copies of the contents of permanent volumes (PersistentVolume) in the Managed Kubernetes cluster at a given point in time.

Snapshots can be used to back up data or move data to another share without having to create a new disk.

In Managed Kubernetes, snapshots work on cloud platform resources.

Create a snapshot

  1. Configure the Volume Snapshot Controller, one of the of CSI Snapshotter components:

    kubectl apply -f https://raw.githubusercontent.com/servercore/mks-csi-snapshotter/master/deploy/setup-snapshot-controller.yaml

    A list of created objects will appear in the response:

    deployment.apps/snapshot-controller created
    serviceaccount/snapshot-controller created
    clusterrole.rbac.authorization.k8s.io/snapshot-controller-runner created
    clusterrolebinding.rbac.authorization.k8s.io/snapshot-controller-role created
    role.rbac.authorization.k8s.io/snapshot-controller-leaderelection created
    rolebinding.rbac.authorization.k8s.io/snapshot-controller-leaderelection created
    customresourcedefinition.apiextensions.k8s.io/volumesnapshots.snapshot.storage.k8s.io created
    customresourcedefinition.apiextensions.k8s.io/volumesnapshotcontents.snapshot.storage.k8s.io created
    customresourcedefinition.apiextensions.k8s.io/volumesnapshotclasses.snapshot.storage.k8s.io created
  2. Check that pods with Volume Snapshot Controller have been created:

    kubectl get pod -l app=snapshot-controller --namespace=kube-system

    A list of pods will appear in the response:

    NAME                                   READY   STATUS    RESTARTS   AGE
    snapshot-controller-7d7f5775d4-cz9j4 1/1 Running 0 3m37s
    snapshot-controller-7d7f5775d4-tc42c 1/1 Running 0 3m37s
  3. Create a yaml file with a manifest for the VolumeSnapshotClass and VolumeSnapshot objects:

    Manifesto example:

    ---
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshotClass
    metadata:
    name: csi-hostpath-snapclass-v1
    driver: cinder.csi.openstack.org
    deletionPolicy: Delete
    parameters:
    force-create: "true"
    ---
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
    name: new-snapshot-demo
    spec:
    volumeSnapshotClassName: csi-hostpath-snapclass-v1
    source:
    persistentVolumeClaimName: my-pv-claim

    Here:

    • csi-hostpath-snapclass-v1 — SnapshotClass object name;
    • new-snapshot-demo — name of the VolumeSnapshot object;
    • my-pv-claim — the name of the PersistentVolumeClaim object whose snapshot you are creating.
  4. Apply the manifest:

    kubectl apply -f <snapshot.yaml>

    Specify <snapshot.yaml> — name of yaml file with manifest for VolumeSnapshotClass and VolumeSnapshot objects.

    The response will show a message that the objects have been created:

    volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass-v1 created
    volumesnapshot.snapshot.storage.k8s.io/new-snapshot-demo created
  5. Make sure that a VolumeSnapshotContent object is created:

    kubectl get volumesnapshotcontents.snapshot.storage.k8s.io

    The response will show the created VolumeSnapshotContent object:

    NAME                                               READYTOUSE   RESTORESIZE   DELETIONPOLICY   DRIVER                     VOLUMESNAPSHOTCLASS         VOLUMESNAPSHOT      VOLUMESNAPSHOTNAMESPACE   AGE
    snapcontent-acc83be5-065f-42c1-a465-9f26497de1b1 Delete cinder.csi.openstack.org csi-hostpath-snapclass-v1 new-snapshot-demo default 9m7s

Restore a persistent volume from a snapshot

  1. Create a yaml file with a manifest to create a new PersistentVolumeClaim from the snapshot.

    Manifesto example:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: snapshot-demo-restore
    spec:
    storageClassName: fast.ru-3b
    dataSource:
    name: new-snapshot-demo
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 10Gi

    Here:

    • snapshot-demo-restore — the name of a new PersistentVolumeClaim object to which the snapshot data will be copied;
    • new-snapshot-demo — name of the snapshot from which you will restore the object.
  2. Apply the manifest:

    kubectl apply -f <snapshot-restore.yaml>

    Specify <snapshot-restore.yaml> — the name of a yaml file with a manifest to create a new PersistentVolumeClaim from the snapshot.

  3. Ensure that a new PersistentVolumeClaim object is created:

    kubectl get pvc

    A new PersistentVolumeClaim will appear in the response:

    NAME          STATUS   VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    snapshot-demo-restore Bound pvc-62394055-3780-4324-8871-1a56a447d70f 10Gi RWO fast.ru-3b 22m