Files
my-rook-config/Documentation/Storage-Configuration/Ceph-CSI/ceph-csi-snapshot.md
T

185 lines
7.1 KiB
Markdown
Raw Normal View History

2020-07-27 13:05:26 +05:30
---
title: Snapshots
---
## Prerequisites
2020-07-27 13:05:26 +05:30
2024-04-17 20:13:06 +05:30
- Install the [snapshot controller and snapshot v1 CRD](https://github.com/kubernetes-csi/external-snapshotter/tree/master#usage).
2020-07-27 13:05:26 +05:30
2022-05-12 19:29:40 +02:00
- We also need a `VolumeSnapshotClass` for volume snapshot to work. The purpose of a `VolumeSnapshotClass` is
2020-07-27 13:05:26 +05:30
defined in [the kubernetes
documentation](https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/).
In short, as the documentation describes it:
2022-05-12 19:29:40 +02:00
!!! info
Just like StorageClass provides a way for administrators to describe the
"classes" of storage they offer when provisioning a volume,
VolumeSnapshotClass provides a way to describe the "classes" of storage when
provisioning a volume snapshot.
## RBD Snapshots
### RBD VolumeSnapshotClass
2022-05-12 19:29:40 +02:00
In [VolumeSnapshotClass](https://github.com/rook/rook/tree/master/deploy/examples/csi/rbd/snapshotclass.yaml),
2020-07-27 13:05:26 +05:30
the `csi.storage.k8s.io/snapshotter-secret-name` parameter should reference the
name of the secret created for the rbdplugin and `pool` to reflect the Ceph pool name.
Update the value of the `clusterID` field to match the namespace that Rook is
running in. When Ceph CSI is deployed by Rook, the operator will automatically
maintain a configmap whose contents will match this key. By default this is
"rook-ceph".
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/rbd/snapshotclass.yaml
2020-07-27 13:05:26 +05:30
```
### Volumesnapshot
2022-05-12 19:29:40 +02:00
In [snapshot](https://github.com/rook/rook/tree/master/deploy/examples/csi/rbd/snapshot.yaml),
2020-07-27 13:05:26 +05:30
`volumeSnapshotClassName` should be the name of the `VolumeSnapshotClass`
previously created. The `persistentVolumeClaimName` should be the name of the
PVC which is already created by the RBD CSI driver.
2020-07-27 13:05:26 +05:30
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/rbd/snapshot.yaml
2020-07-27 13:05:26 +05:30
```
### Verify RBD Snapshot Creation
```console
2022-05-12 19:29:40 +02:00
$ kubectl get volumesnapshotclass
NAME DRIVER DELETIONPOLICY AGE
csi-rbdplugin-snapclass rook-ceph.rbd.csi.ceph.com Delete 3h55m
2020-07-27 13:05:26 +05:30
```
```console
2022-05-12 19:29:40 +02:00
$ kubectl get volumesnapshot
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
rbd-pvc-snapshot true rbd-pvc 1Gi csi-rbdplugin-snapclass snapcontent-79090db0-7c66-4b18-bf4a-634772c7cac7 3h50m 3h51m
```
The snapshot will be ready to restore to a new PVC when the `READYTOUSE` field of the
2020-07-27 13:05:26 +05:30
`volumesnapshot` is set to true.
### Restore the RBD snapshot to a new PVC
2020-07-27 13:05:26 +05:30
2022-05-12 19:29:40 +02:00
In [pvc-restore](https://github.com/rook/rook/tree/master/deploy/examples/csi/rbd/pvc-restore.yaml),
2020-07-27 13:05:26 +05:30
`dataSource` should be the name of the `VolumeSnapshot` previously
2024-05-13 10:01:07 +05:30
created. The `dataSource` kind should be the `VolumeSnapshot`. The `storageClassName`
can be any RBD storageclass.
Please Note:
* `provisioner` must be the same for both the Parent PVC and the restored PVC.
* The non-encrypted PVC cannot be restored to an encrypted one and vice-versa.
* encrypted -> encrypted (possible)
* non-encrypted -> non-encrypted (possible)
* encrypted -> non-encrypted (not possible)
* non-encrypted -> encrypted (not possible)
2020-07-27 13:05:26 +05:30
Create a new PVC from the snapshot
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/rbd/pvc-restore.yaml
2020-07-27 13:05:26 +05:30
```
### Verify RBD Clone PVC Creation
```console
2022-05-12 19:29:40 +02:00
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
rbd-pvc Bound pvc-84294e34-577a-11e9-b34f-525400581048 1Gi RWO rook-ceph-block 34m
rbd-pvc-restore Bound pvc-575537bf-577f-11e9-b34f-525400581048 1Gi RWO rook-ceph-block 8s
2020-07-27 13:05:26 +05:30
```
## RBD snapshot resource Cleanup
To clean your cluster of the resources created by this example, run the following:
```console
2021-09-22 10:37:07 +02:00
kubectl delete -f deploy/examples/csi/rbd/pvc-restore.yaml
kubectl delete -f deploy/examples/csi/rbd/snapshot.yaml
kubectl delete -f deploy/examples/csi/rbd/snapshotclass.yaml
2020-07-27 13:05:26 +05:30
```
## CephFS Snapshots
### CephFS VolumeSnapshotClass
2022-05-12 19:29:40 +02:00
In [VolumeSnapshotClass](https://github.com/rook/rook/tree/master/deploy/examples/csi/cephfs/snapshotclass.yaml),
the `csi.storage.k8s.io/snapshotter-secret-name` parameter should reference the
name of the secret created for the cephfsplugin.
In the volumesnapshotclass, update the value of the `clusterID` field to match the namespace that Rook is
running in. When Ceph CSI is deployed by Rook, the operator will automatically
maintain a configmap whose contents will match this key. By default this is
"rook-ceph".
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/cephfs/snapshotclass.yaml
```
2022-05-12 19:29:40 +02:00
### VolumeSnapshot
2022-05-12 19:29:40 +02:00
In [snapshot](https://github.com/rook/rook/tree/master/deploy/examples/csi/cephfs/snapshot.yaml),
`volumeSnapshotClassName` should be the name of the `VolumeSnapshotClass`
previously created. The `persistentVolumeClaimName` should be the name of the
PVC which is already created by the CephFS CSI driver.
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/cephfs/snapshot.yaml
```
### Verify CephFS Snapshot Creation
```console
2022-05-12 19:29:40 +02:00
$ kubectl get volumesnapshotclass
NAME DRIVER DELETIONPOLICY AGE
csi-cephfslugin-snapclass rook-ceph.cephfs.csi.ceph.com Delete 3h55m
```
2022-05-12 19:29:40 +02:00
```console
$ kubectl get volumesnapshot
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
cephfs-pvc-snapshot true cephfs-pvc 1Gi csi-cephfsplugin-snapclass snapcontent-34476204-a14a-4d59-bfbc-2bbba695652c 3h50m 3h51m
```
The snapshot will be ready to restore to a new PVC when `READYTOUSE` field of the
`volumesnapshot` is set to true.
### Restore the CephFS snapshot to a new PVC
In
2022-05-12 19:29:40 +02:00
[pvc-restore](https://github.com/rook/rook/tree/master/deploy/examples/csi/cephfs/pvc-restore.yaml),
`dataSource` should be the name of the `VolumeSnapshot` previously
created. The `dataSource` kind should be the `VolumeSnapshot`.
Create a new PVC from the snapshot
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/cephfs/pvc-restore.yaml
```
### Verify CephFS Restore PVC Creation
```console
2022-05-12 19:29:40 +02:00
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
cephfs-pvc Bound pvc-74734901-577a-11e9-b34f-525400581048 1Gi RWX rook-cephfs 55m
cephfs-pvc-restore Bound pvc-95308c75-6c93-4928-a551-6b5137192209 1Gi RWX rook-cephfs 34s
```
## CephFS snapshot resource Cleanup
To clean your cluster of the resources created by this example, run the following:
```console
2021-09-22 10:37:07 +02:00
kubectl delete -f deploy/examples/csi/cephfs/pvc-restore.yaml
kubectl delete -f deploy/examples/csi/cephfs/snapshot.yaml
kubectl delete -f deploy/examples/csi/cephfs/snapshotclass.yaml
```
## Limitations
2022-05-12 19:29:40 +02:00
- There is a limit of 400 snapshots per cephFS filesystem.
- The PVC cannot be deleted if it has snapshots. make sure all the snapshots on the PVC are deleted before you delete the PVC.