Setting up snapshots for File Storage for VPC
Virtual Private Cloud
File Storage for VPC volume snapshots provide you with a standardized way to copy a volume's contents at a particular point in time without creating an entirely new volume. Snapshots are supported for both zonal(dp2) and regional (rfs) based storage classes. For more information about snapshots, see How snapshots work.
For more information about File Storage for VPC, see About File Storage for VPC.
Snapshots support for the File Storage for VPC add-on is currently in Beta.
If the PVC (file share) is deleted, then all the corresponding snapshots owned by the file share are deleted. In this case CSI volume snapshots remain, but the backend snapshots in VPC will not exists. Therefore, you must delete volumes by using
oc delete vs <snapshot-name>.
Prerequisites
- Make sure you have the File Storage for VPC add-on installed in your cluster.
- Make sure you have Share Snapshot Operator permissions in IAM.
Creating an app
Create an example Persistent Volume Claim (PVC) and deploy a pod that references that claim.
-
Verify that the add-on state is
normaland the status isReady.ibmcloud oc cluster addon ls --cluster CLUSTER-IDName Version Health State Health Status vpc-file-csi-driver 2.0 normal Addon Ready. For more info: http://ibm.biz/addon-state (H1500) -
Verify that the driver pods are deployed and the status is
Running.oc get pods -n kube-system | grep vpc-file-csiExample output
ibm-vpc-file-csi-controller-s34sw 7/7 Running 0 77s ibm-vpc-file-csi-controller-7hdhd 7/7 Running 0 77s ibm-vpc-file-csi-node-56c85 4/4 Running 0 77s ibm-vpc-file-csi-node-87j2t 4/4 Running 0 77s ibm-vpc-file-csi-node-cmh2h 4/4 Running 0 77s -
Create a PVC.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: csi-file-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: ibmc-vpc-file-min-iopsoc create -f pvc.yaml -
Verify that the PVC is created and is in a
Boundstate.oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE csi-file-pvc Bound pvc-9873bd7e-41a8-4234-a9bf-271b8ca7e4f9 10Gi RWM ibmc-vpc-file-min-iops <unset> 5 -
Create a YAML configuration file for a deployment that mounts the PVC that you created.
apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment labels: app: my-deployment spec: replicas: 1 selector: matchLabels: app: my-deployment template: metadata: labels: app: my-deployment spec: containers: - image: nginx # Your containerized app image name: container-name volumeMounts: - mountPath: /myvolumepath # Mount path for PVC name: my-vol # Volume mount name volumes: - name: my-vol # Volume resource name persistentVolumeClaim: claimName: csi-file-pvc # The name of the PVC you created earlieroc create -f pod.yaml -
Verify that the pod is running in your cluster.
oc get podsNAME READY STATUS RESTARTS AGE my-deployment-58dd7c89b6-8zdcl 1/1 Running 0 4m50s -
Now that you have created the pod, log in to the pod and create a text file to use for the snapshot.
oc exec -it POD_NAME -- /bin/bashExample commands to create a new text file.
root@my-deployment-58dd7c89b6-8zdcl:/# cd myvolumepath/ root@my-deployment-58dd7c89b6-8zdcl:/myvolumepath# echo "hi" > new.txt root@my-deployment-58dd7c89b6-8zdcl:/myvolumepath# exit
Creating a volume snapshot
After you create a deployment and a PVC, you can create the volume snapshots.
-
Make sure you have Share Snapshot Operator permissions in IAM.
-
Create a volume snapshot in your cluster by using the
ibmc-vpcfile-snapshot-deletesnapshot class that is deployed when you enabled the add-on. Save the following VolumeSnapshot configuration to a file calledsnapvol.yaml.apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: snapshot-csi-file-pvc spec: volumeSnapshotClassName: ibmc-vpcfile-snapshot-delete source: persistentVolumeClaimName: csi-file-pvcoc create -f snapvol.yaml -
Verify that the snapshot is ready to use.
oc get volumesnapshotsExample output where
READYTOUSEistrue.NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE ibmc-vpcfile-snapshot-delete true csi-file-pvc 10Gi ibmc-vpcfile-snapshot-delete snapcontent-9c374fbf-43a6-48d6-afc5-e76e1ab7c12b 18h 18h
Restoring from a volume snapshot
After you deploy the volume snapshot, you can restore data to a new volume by using the snapshot. Creating a PVC dynamically provisions a new volume with snapshot data.
-
Create a second PVC that references your volume snapshot.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: restore-pvc spec: storageClassName: ibmc-vpc-file-min-iops dataSource: name: snapshot-csi-file-pvc kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteMany resources: requests: storage: 10Gi -
Verify that the PVC is created and is in a
Boundstate.oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE csi-file-pvc Bound pvc-9873bd7e-41a8-4234-a9bf-271b8ca7e4f9 10Gi RWM ibmc-vpc-file-min-iops <unset> 9m16s restore-pvc Bound pvc-04dc8d6c-ac75-48b1-989d-ed67deb35911 10Gi RWM ibmc-vpc-file-min-iops <unset> 116s -
Create a second YAML configuration file for a deployment that mounts the PVC that you created.
apiVersion: apps/v1 kind: Deployment metadata: name: restore-pod labels: app: restore-pod spec: replicas: 1 selector: matchLabels: app: restore-pod template: metadata: labels: app: restore-pod spec: containers: - image: nginx # Your containerized app image name: container-name volumeMounts: - mountPath: /myvolumepath # Mount path for pvc from container name: my-vol # Volume mount name volumes: - name: my-vol # Volume resource name persistentVolumeClaim: claimName: restore-pvc # The name of the PVC that you created earlieroc create -f restore-pod.yaml -
Verify that the pod is created.
oc get podsNAME READY STATUS RESTARTS AGE restore-pod-1 1/1 Running 0 30m pod-2 1/1 Running 0 46h -
Log in to the newly created pod and verify that the sample text file you created earlier is saved to the new pod.
oc exec -it POD_NAME -- /bin/bash root@POD_NAME :/# cd myvolumepath/ root@POD_NAME :/myvolumepath# ls lost+found new.txt root@POD_NAME :/myvolumepath# cat new.txtExample output
hi
Restoring static snapshots
Complete the following steps to restore a static snapshot.
-
Get snapshot CRN using
ibmcloud is share-snapshot <share-id> <share-snapshot-id> | grep CRNExample output
CRN crn:v1:staging:public:is:us-south-3:a/77f2bceddaeb577dcaddb4073fe82c1c::share-snapshot:r134-1b3af00c-7a07-4ba7-b005-f6723c5b5e98/r134-164521b1-f5c1-4968-9605-a7aaa7e6cd2f -
Create a
VolumeSnapshotContentresource. Save the following configuration as a file calledvolsnapcontent.yaml.apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotContent metadata: name: static-file-snapshot-cnt spec: volumeSnapshotClassName: ibmc-vpcfile-snapshot-retain deletionPolicy: Retain driver: vpc.file.csi.ibm.io source: snapshotHandle: crn:v1:staging:public:is:us-south-3:a/77f2bceddaeb577dcaddb4073fe82c1c::share-snapshot:r134-1b3af00c-7a07-4ba7-b005-f6723c5b5e98/r134-164521b1-f5c1-4968-9605-a7aaa7e6cd2f # Enter the CRN of the snapshot you created earlier. For example crn:v1:public:is:us-south:a/8ee729d7f903db130b00257d91b6977f::snapshot:r134-64c3ad8e-786e-4f54-9b63-388615811ba6 volumeSnapshotRef: name: static-file-snapshot namespace: defaultoc apply -f volsnapcontent.yamlExample output
volumesnapshot.snapshot.storage.k8s.io/crossaccount-snapshot created -
Create a VolumeSnapshot. Save the following configuration as a file called volsnap.yaml.
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: static-file-snapshot namespace: default spec: volumeSnapshotClassName: ibmc-vpcfile-snapshot-retain source: volumeSnapshotContentName: static-file-snapshot-cnt # Enter the name of the VolumeSnapshotContent that you created in the previous step.oc apply -f volsnap.yaml -
Create a PVC. Save the following configuration as a file called
pvc2.yaml.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: restore-static-pvc spec: storageClassName: ibmc-vpc-file-min-iops dataSource: name: static-file-snapshot kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteMany resources: requests: storage: 10Gioc apply -f pvc2.yamlRedeploy your app.
apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment labels: app: my-deployment spec: replicas: 1 selector: matchLabels: app: my-deployment template: metadata: labels: app: my-deployment spec: containers: - image: nginx # Your containerized app image name: container-name volumeMounts: - mountPath: /myvolumepath # Mount path for PVC name: my-vol # Volume mount name volumes: - name: my-vol # Volume resource name persistentVolumeClaim: claimName: restore-static-pvc # The name of the PVC you created earlieroc create -f dep2.yaml -
Verify that the pod is running in your cluster.
oc get podsNAME READY STATUS RESTARTS AGE my-deployment-58dd7c89b6-8zdcl 1/1 Running 0 4m50s -
Log in to the newly created pod and verify that the sample text file you created earlier is saved to the new pod.
root@my-deployment-static-768f64ffcf-h6qft:/# cd myvolumepath/ root@my-deployment-static-768f64ffcf-h6qft:/myvolumepath# ls new.txt root@my-deployment-static-768f64ffcf-h6qft:/myvolumepath# cat new.txt hi
Turning off snapshots
By default, snapshot functionality is enabled when using the File Storage for VPC. This functionality can be turned off in the configmap addon-vpc-file-csi-driver-configmap in the kube-system namespace by changing the
IsSnapshotEnabled to false. Note that with this change in the configmap, any snapshots that are created fail with the message:CreateSnapshot functionality is disabled.
-
Save the current configmap from your cluster to your local machine.
oc get cm -n kube-system addon-vpc-file-csi-driver-configmap -o yaml >> snapshotconfigmap.yaml -
Edit the
IS_SNAPSHOT_ENABLEDparamter tofalse.IS_SNAPSHOT_ENABLED:false -
Save the file and apply your changes.
oc apply -f snapshotconfigmap.yaml