Data Protection and Snapshots
Setup CSI Volume Snapshotting
In order to use VolumeSnapshots with the Portworx CSI Driver and Portworx Operator, you must enable Snapshot Controller in your StorageCluster. By default, installSnapshotController
is set to true
when you enable CSI in the StorageCluster.
Run the following command to edit the StorageCluster
and update the arguments if CSI is not enabled:
kubectl edit stc <StorageClustername> -n kube-system
csi:
enabled: true
installSnapshotController: true
Take local snapshots of CSI-enabled volumes
For Kubernetes 1.20+, CSI Snapshotting is supported by the Portworx CSI Driver.
CSI Snapshots only support local volume snapshots.
If you already have a CSI PVC, complete the following steps to create and restore a CSI VolumeSnapshot.
Create a VolumeSnapshotClass, specifying the following:
- The
snapshot.storage.kubernetes.io/is-default-class: "true"
annotation - The
csi.storage.k8s.io/snapshotter-secret-name
parameter with your encryption and/or authorization secret - The
csi.storage.k8s.io/snapshotter-secret-namespace
parameter with the namespace your secret is in
noteSpecify
snapshotter-secret-name
andsnapshotter-secret-namespace
if px-security isENABLED
.See enable security in Portworx for more information.
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: px-csi-snapclass
annotations:
snapshot.storage.kubernetes.io/is-default-class: "true"
driver: pxd.portworx.com
deletionPolicy: Delete
parameters: ## Specify only if px-security is ENABLED
csi.storage.k8s.io/snapshotter-secret-name: px-user-token
csi.storage.k8s.io/snapshotter-secret-namespace: kube-system
csi.openstorage.org/snapshot-type: local- The
Create a VolumeSnapshot:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: px-csi-snapshot
spec:
volumeSnapshotClassName: px-csi-snapclass
source:
persistentVolumeClaimName: px-mysql-pvcnoteVolumeSnapshot objects are namespace-scoped and should be created in the same namespace as the PVC.
Restore from a VolumeSnapshot:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: px-csi-pvc-restored
spec:
storageClassName: px-csi-db
dataSource:
name: px-csi-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
See the Kubernetes-CSI snapshotting documentation for more examples and documentation.