Setting up snapshots with the Block Storage for VPC cluster add-on
Virtual Private Cloud
Block 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. For more information about snapshots, see How snapshots work. For more information about Block Storage for VPC, see About Block Storage for VPC.
Snapshots support is available for cluster version 1.25 and later and with the Block Storage for VPC cluster add-on version 5.0 and later.
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 ks cluster addon ls --cluster CLUSTER-IDName Version Health State Health Status vpc-block-csi-driver 5.2 normal Addon Ready. For more info: http://ibm.biz/addon-state (H1500) -
Verify that the driver pods are deployed and the status is
Running.kubectl get pods -n kube-system | grep vpc-block-csiExample output
ibm-vpc-block-csi-controller-0 7/7 Running 0 77s ibm-vpc-block-csi-node-56c85 4/4 Running 0 77s ibm-vpc-block-csi-node-87j2t 4/4 Running 0 77s ibm-vpc-block-csi-node-cmh2h 4/4 Running 0 77s -
Create a PVC.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: csi-block-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: ibmc-vpc-block-5iops-tierkubectl create -f pvc.yaml -
Verify that the PVC is created and is in a
Boundstate.kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE csi-block-pvc Bound pvc-0798b499-0b61-4f57-a184-4caeb7b9298d 10Gi RWO ibmc-vpc-block-5iops-tier 4m22s -
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-block-pvc # The name of the PVC you created earlierkubectl create -f pod.yaml -
Verify that the pod is running in your cluster.
kubectl 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.
kubectl exec -it POD_NAME /bin/bashExample output
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 snapshot resources.
You can creating snapshots only when a volume is attached to a pod.
-
Create a volume snapshot resource in your cluster by using the
ibmc-vpcblock-snapshotsnapshot 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-block-pvc spec: volumeSnapshotClassName: ibmc-vpcblock-snapshot source: persistentVolumeClaimName: csi-block-pvckubectl create -f snapvol.yaml -
Verify that the snapshot is ready to use.
kubectl get volumesnapshotsExample output where
READYTOUSEistrue.NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE ibmc-vpcblock-snapshot true csi-block-pvc 1Gi ibmc-vpcblock-snapshot snapcontent-9c374fbf-43a6-48d6-afc5-e76e1ab7c12b 18h 18h
Restoring from a volume snapshot
After you deploy the snapshot resources, 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-block-5iops-tier dataSource: name: snapshot-csi-block-pvc kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 10Gi -
Verify that the PVC is created and is in a
Boundstate.kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE restore-pvc Bound pvc-4ede7630-5a49-4bae-b34d-dc528acfb884 10Gi RWO ibmc-vpc-block-5iops-tier 18h -
Create a second YAML configuration file for a deployment that mounts the PVC that you created.
apiVersion: apps/v1 kind: Deployment metadata: name: podtwo labels: app: podtwo spec: replicas: 1 selector: matchLabels: app: podtwo template: metadata: labels: app: podtwo 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 earlierkubectl create -f podtwo.yaml -
Verify that the pod is created.
kubectl get podsNAME READY STATUS RESTARTS AGE POD_NAME 1/1 Running 0 30m POD2_NAME 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.
kubectl 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
Turning off snapshots
By default, snapshot functionality is enabled when using the Block Storage for VPC. This functionality can be turned off in the configmap addon-vpc-block-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.
kubectl get cm -n kube-system addon-vpc-block-csi-driver-configmap -o yaml >> snapshotconfigmap.yaml -
Edit the
IsSnapshotEnabledparameter tofalse. -
Save the file and apply your changes.
kubectl apply -f snapshotconfigmap.yaml
Next steps
Deploy the snapshot validation webhook to validate user input. For more information, see Deploying the snapshot validation webhook.
Troubleshooting snapshots
Review the following troubleshooting topics.