CSI volume cloning
Container Storage Interface (CSI) volume cloning duplicates existing persistent volumes to create independent copies for data protection, testing, or deployment. You can use cloning to create new volumes from existing data without manual copying or backup restoration.
Overview of CSI volume cloning
You can use Container Storage Interface (CSI) volume clones to create point-in-time duplicates of existing persistent volumes.
Volume cloning is similar to volume snapshots, although it is more efficient. For example, a cluster administrator can duplicate a cluster volume by creating another instance of the existing cluster volume.
Cloning creates an exact duplicate of the specified volume on the back-end device, rather than creating a new empty volume. After dynamic provisioning, you can use a volume clone just as you would use any standard volume.
No new API objects are required for cloning. The existing dataSource field in the PersistentVolumeClaim object is expanded so that it can accept the name of an existing PersistentVolumeClaim in the same namespace.
Before you provision a CSI volume clone, you should be familiar with persistent volumes. For information about persistent volumes, see Understanding persistent volumes in Additional resources.
Support limitations
By default, OpenShift Container Platform supports CSI volume cloning with these limitations:
- The destination persistent volume claim (PVC) must exist in the same namespace as the source PVC.
- Cloning is supported with a different Storage Class.
- Destination volume can be the same for a different storage class as the source.
- You can use the default storage class and omit
storageClassNamein thespec.
- Support is only available for CSI drivers. In-tree and FlexVolumes are not supported.
- CSI drivers might not have implemented the volume cloning functionality. For details, see the CSI driver documentation.
Provisioning a CSI volume clone
Create a new persistent volume claim (PVC) that specifies an existing PVC as its data source. The new volume automatically populates with a copy of the source PVC’s data and must be created in the same namespace as the source.
When you create a cloned persistent volume claim (PVC) API object, you trigger the provisioning of a CSI volume clone. The clone pre-populates with the contents of another PVC, adhering to the same rules as any other persistent volume. The one exception is that you must add a dataSource that references an existing PVC in the same namespace.
Prerequisites
- You are logged in to a running OpenShift Container Platform cluster.
- Your PVC is created using a CSI driver that supports volume cloning.
- Your storage back end is configured for dynamic provisioning. Cloning support is not available for static provisioners.
Procedure
-
Create and save a file with the
PersistentVolumeClaimobject described by the following YAML:Example pvc-clone.yamlapiVersion: v1kind: PersistentVolumeClaimmetadata:name: pvc-1-clonenamespace: mynamespacespec:storageClassName: csi-cloningaccessModes:- ReadWriteOnceresources:requests:storage: 5GidataSource:kind: PersistentVolumeClaimname: pvc-1Where
spec.storageClassNameis the name of the storage class that provisions the storage back end. The default storage class can be used andstorageClassNamecan be omitted in the spec. -
Create the object you saved in the previous step by running the following command:
$ oc create -f pvc-clone.yamlA new PVC
pvc-1-cloneis created. -
Verify that the volume clone was created and is ready by running the following command:
$ oc get pvc pvc-1-cloneThe
pvc-1-cloneshows that it isBound.You are now ready to use the newly cloned PVC to configure a pod.
-
Create and save a file with the
Podobject described by the YAML. For example:Example pod YAML filekind: PodapiVersion: v1metadata:name: mypodspec:containers:- name: myfrontendimage: dockerfile/nginxvolumeMounts:- mountPath: "/var/www/html"name: mypdvolumes:- name: mypdpersistentVolumeClaim:claimName: pvc-1-cloneWhere
spec.volumes.persistentVolumeClaim.claimNameis the cloned PVC created during the CSI volume cloning operation.
Result
The created Pod object is now ready to consume, clone, snapshot, or delete your cloned PVC independently of its original dataSource PVC.
Additional resources