ceph-csi/docs/cephfs-snap-clone.md
Prasanna Kumar Kalever 2945f7b669 cleanup: stick to standards when using dollar-sign in md
MD014 - Dollar signs used before commands without showing output
The dollar signs are unnecessary, it is easier to copy and paste and
less noisy if the dollar signs are omitted. Especially when the
command doesn't list the output, but if the command follows output
we can use `$ ` (dollar+space) mainly to differentiate between
command and its ouput.

scenario 1: when command doesn't follow output
```console
cd ~/work
```

scenario 2: when command follow output (use dollar+space)
```console
$ ls ~/work
file1 file2 dir1 dir2 ...
```

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
2020-11-11 13:18:05 +00:00

4.4 KiB

Create CephFS snapshot and Clone Volume

Prerequisite

  • For snapshot functionality to be supported for your Kubernetes cluster, the Kubernetes version running in your cluster should be >= v1.17. We also need the snapshot controller deployed in your Kubernetes cluster along with csi-snapshotter sidecar container. Refer external-snapshotter for more information on these sidecar controllers. There should be a volumesnapshotclass object present in the cluster for snapshot request to be satisified.

    • To install snapshot controller and CRD

      ./scripts/install-snapshot.sh install
      

      To install from specific external-snapshotter version, you can leverage SNAPSHOT_VERSION variable, for example:

      SNAPSHOT_VERSION="v3.0.1" ./scripts/install-snapshot.sh install
      
    • In the future, you can choose to cleanup by running

      ./scripts/install-snapshot.sh cleanup
      

NOTE: At present, there is a limit of 400 snapshots per cephFS filesystem. Also PVC cannot be deleted if it's having snapshots. Make sure all the snapshots on the PVC are deleted before you delete the PVC.

Snapshot

Create snapshotclass

kubectl create -f ../examples/cephfs/snapshotclass.yaml

Create snapshot

The snapshot is created on/for an existing PVC. You should have a PVC in bound state before creating snapshot from it. It is recommended to create a volume snapshot or a PVC clone only when the PVC is not in use. Please refer pvc creation doc for more information on how to create a PVC.

  • Verify if PVC is in Bound state
$ kubectl get pvc
NAME              STATUS        VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
csi-cephfs-pvc    Bound         pvc-1ea51547-a88b-4ab0-8b4a-812caeaf025d   1Gi        RWX            csi-cephfs-sc  20h
  • Create snapshot of the bound PVC
$ kubectl create -f ../examples/cephfs/snapshot.yaml
volumesnapshot.snapshot.storage.k8s.io/cephfs-pvc-snapshot created
  • Get details about the snapshot
$ kubectl get volumesnapshot
NAME                  READYTOUSE   SOURCEPVC       SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS                SNAPSHOTCONTENT                                    CREATIONTIME   AGE
cephfs-pvc-snapshot   true         csi-cephfs-pvc                          1Gi           csi-cephfsplugin-snapclass   snapcontent-34476204-a14a-4d59-bfbc-2bbba695652c   3s             6s
  • Get details about the volumesnapshotcontent
$ kubectl get volumesnapshotcontent
NAME                                               READYTOUSE   RESTORESIZE   DELETIONPOLICY   DRIVER                VOLUMESNAPSHOTCLASS          VOLUMESNAPSHOT        AGE
snapcontent-34476204-a14a-4d59-bfbc-2bbba695652c   true         1073741824    Delete           cephfs.csi.ceph.com   csi-cephfsplugin-snapclass   cephfs-pvc-snapshot   64s

Restore snapshot to a new PVC

kubectl create -f ../examples/cephfs/pvc-restore.yaml
$ kubectl get pvc
NAME                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
csi-cephfs-pvc       Bound    pvc-1ea51547-a88b-4ab0-8b4a-812caeaf025d   1Gi        RWX            csi-cephfs-sc  20h
cephfs-pvc-restore   Bound    pvc-95308c75-6c93-4928-a551-6b5137192209   1Gi        RWX            csi-cephfs-sc  11m

Clone PVC

kubectl create -f ../examples/cephfs/pvc-clone.yaml
$ kubectl get pvc
NAME                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
csi-cephfs-pvc       Bound    pvc-1ea51547-a88b-4ab0-8b4a-812caeaf025d   1Gi        RWX            csi-cephfs-sc  20h
cephfs-pvc-clone     Bound    pvc-b575bc35-d521-4c41-b4f9-1d733cd28fdf   1Gi        RWX            csi-cephfs-sc  39s
cephfs-pvc-restore   Bound    pvc-95308c75-6c93-4928-a551-6b5137192209   1Gi        RWX            csi-cephfs-sc  55m