Snapshots of persistent volumes in a Managed Kubernetes cluster
VolumeSnapshots are copies of the contents of PersistentVolumes in a Managed Kubernetes cluster at a particular 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 run on cloud platform resources.
Create a snapshot
-
Configure the Volume Snapshot Controller, one of the components of CSI Snapshotter:
kubectl apply -f https://raw.githubusercontent.com/selectel/mks-csi-snapshotter/master/deploy/setup-snapshot-controller.yamlThe response will list the objects created. For example:
deployment.apps/snapshot-controller createdserviceaccount/snapshot-controller createdclusterrole.rbac.authorization.k8s.io/snapshot-controller-runner createdclusterrolebinding.rbac.authorization.k8s.io/snapshot-controller-role createdrole.rbac.authorization.k8s.io/snapshot-controller-leaderelection createdrolebinding.rbac.authorization.k8s.io/snapshot-controller-leaderelection createdcustomresourcedefinition.apiextensions.k8s.io/volumesnapshots.snapshot.storage.k8s.io createdcustomresourcedefinition.apiextensions.k8s.io/volumesnapshotcontents.snapshot.storage.k8s.io createdcustomresourcedefinition.apiextensions.k8s.io/volumesnapshotclasses.snapshot.storage.k8s.io created -
Make sure that pods with Volume Snapshot Controller are created:
kubectl get pod -l app=snapshot-controller --namespace=kube-systemA list of pods will appear in the response. For example:
NAME READY STATUS RESTARTS AGEsnapshot-controller-7d7f5775d4-cz9j4 1/1 Running 0 3m37ssnapshot-controller-7d7f5775d4-tc42c 1/1 Running 0 3m37s -
Create a yaml file with a manifest for the VolumeSnapshotClass and VolumeSnapshot objects:
Manifesto example:
---apiVersion: snapshot.storage.k8s.io/v1kind: VolumeSnapshotClassmetadata:name: csi-hostpath-snapclass-v1driver: cinder.csi.openstack.orgdeletionPolicy: Deleteparameters:force-create: "true"---apiVersion: snapshot.storage.k8s.io/v1kind: VolumeSnapshotmetadata:name: new-snapshot-demospec:volumeSnapshotClassName: csi-hostpath-snapclass-v1source:persistentVolumeClaimName: my-pv-claimHere:
csi-hostpath-snapclass-v1- name of the SnapshotClass object;new-snapshot-demo- name of the VolumeSnapshot object;my-pv-claim- the name of the PersistentVolumeClaim object whose snapshot you are creating.
-
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>- the name of the yaml file with the manifest for VolumeSnapshotClass and VolumeSnapshot objects. For example,snapshot.yaml.The response will show a message that the objects have been created. For example:
volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass-v1 createdvolumesnapshot.snapshot.storage.k8s.io/new-snapshot-demo created -
Make sure that a VolumeSnapshotContent object is created:
kubectl get volumesnapshotcontents.snapshot.storage.k8s.ioThe created VolumeSnapshotContent object will appear in the response. For example:
NAME READYTOUSE RESTORESIZE DELETIONPOLICY DRIVER VOLUMESNAPSHOTCLASS VOLUMESNAPSHOT VOLUMESNAPSHOTNAMESPACE AGEsnapcontent-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
-
Create a yaml file with a manifest to create a new PersistentVolumeClaim from the snapshot.
Manifesto example:
apiVersion: v1kind: PersistentVolumeClaimmetadata:name: snapshot-demo-restorespec:storageClassName: fast.ru-3bdataSource:name: new-snapshot-demokind: VolumeSnapshotapiGroup: snapshot.storage.k8s.ioaccessModes:- ReadWriteOnceresources:requests:storage: 10GiHere:
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.
-
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>is the name of the yaml file with the manifest to create a new PersistentVolumeClaim from the snapshot. For example,snapshot-restore.yaml. -
Ensure that a new PersistentVolumeClaim object is created:
kubectl get pvcA new PersistentVolumeClaim will appear in the response. For example:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEsnapshot-demo-restore Bound pvc-62394055-3780-4324-8871-1a56a447d70f 10Gi RWO fast.ru-3b 22m