This document describes how to use volume cloning with supported Container Storage Interface (CSI) drivers to protect against data loss in OKD. Familiarity with persistent volumes is suggested.

CSI volume cloning is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.

For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.

Overview of CSI volume cloning

A Container Storage Interface (CSI) volume clone represents a duplicate of an existing persistent volume that is its own unique volume on the system at a particular point in time. With cloning, the back-end device creates an exact duplicate of the specified volume, rather than creating a new empty volume. After it has been dynamically provisioned, a volume clone can be consumed as any standard volume would be.

Volume cloning is similar to volume snapshots, although it offers a more efficient method for creating a pre-populated volume copy. For example, a cluster administrator can duplicate a cluster volume by creating another instance of the existing cluster volume.

There are no new API objects required for cloning. The existing dataSource field in the PersistentVolumeClaim object is expanded to be able to accept the name of an existing PersistentVolumeClaim in the same namespace.

OKD supports CSI volume cloning by default. Be aware that:

  • Support is only available for CSI drivers. In-tree and FlexVolumes are not supported.

  • OKD does not ship with any CSI drivers. It is recommended to use the CSI drivers provided by community or storage vendors. Follow the installation instructions provided by the CSI driver.

  • CSI drivers may or may not have implemented the volume cloning functionality. See documentation provided by the CSI driver for details.

  • OKD Latest supports version 1.1.0 of the CSI specification.

Provisioning a CSI volume clone

Provisioning of a CSI volume clone is triggered by the creation of a cloned persistent volume claim (PVC) API object. The cloned PVC is pre-populated with the contents of another PVC. After creation, the cloned volume adheres to the same rules as any other persistent volume.

Prerequisites
  • Logged in to a running OKD cluster.

  • A PVC created using a CSI driver that supports volume cloning.

  • Storage back end is configured for dynamic provisioning. Cloning support is not available for static provisioners.

  • Source and destination PVCs must exist in the same namespace.

  • Source and destination storage class must be the same.

Procedure

Clones are provisioned like any other PVC, with the exception of adding a dataSource that references an existing PVC in the same namespace.

To clone a PVC from an existing PVC:

  1. Define the PersistentVolumeClaim object as shown in the following example:

    pvc-clone.yaml
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-1-clone
      namespace: mynamespace
    spec:
      storageClassName: csi-cloning (1)
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
    1 Name of the storage class that provisions the storage back end. Default storage class can be used and storageClassName can be omitted in the spec.
  2. Create the object you saved in the previous step by running the following command:

    $ oc create -f pvc-clone.yaml

    A new PVC pvc-1-clone is created.

  3. Verify that the volume clone was created and is ready by running the following command:

    $ oc get pvc pvc-1-clone

    The pvc-1-clone shows that it is Bound.

Using a cloned PVC as a storage volume

A newly cloned persistent volume claim (PVC) can be consumed, cloned, snapshotted, or deleted independently of its original dataSource PVC.

Pods can access storage by using the cloned PVC as a volume. For example:

Use CSI volume clone in the Pod
kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: dockerfile/nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: pvc-1-clone (1)
1 The cloned PVC created during the CSI volume cloning operation.