While snapshots are a copy of a certain state of PVs, it is not the only way to create a copy of data. CSI also allows new volumes to be created from existing volumes. In this recipe, we will create a PVC using an existing PVC by performing the following steps:
- Get the list of PVCs. You may have more than one PVC. In this example, we will use the PVC we created in the Creating a volume snapshot recipe. You can use another PVC as long as it has been created using the CSI driver that supports VolumePVCDataSource APIs:
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
csi-ebs-pvc Bound pvc-574ed379-71e1-4548-b736-7137ab9cfd9d 4Gi RWO aws-csi-ebs 23h
- Create a PVC using an existing PVC (in this recipe, this is csi-ebs-pvc) as the dataSource. The data source can be either a VolumeSnapshot or PVC. In this example, we used PersistentVolumeClaim to clone the data:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: clone-of-csi-ebs-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi
dataSource:
kind: PersistentVolumeClaim
name: csi-ebs-pvc
EOF
With that, you've learned a simple way of cloning persistent data from an existing data source.