From 023b7f87280c2feb174839a8eb3d8b0cb3275b94 Mon Sep 17 00:00:00 2001 From: umagnus Date: Tue, 28 Nov 2023 08:14:35 +0000 Subject: [PATCH] add volume cloning doc --- README.md | 1 + deploy/example/cloning/README.md | 65 +++++++++++++++++++ .../cloning/nginx-pod-restored-cloning.yaml | 23 +++++++ .../pvc-nfs-cloning.yaml} | 2 +- deploy/example/nginx-pod-nfs.yaml | 23 +++++++ hack/verify-yamllint.sh | 2 +- 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 deploy/example/cloning/README.md create mode 100644 deploy/example/cloning/nginx-pod-restored-cloning.yaml rename deploy/example/{pvc-volume-clone.yaml => cloning/pvc-nfs-cloning.yaml} (91%) create mode 100644 deploy/example/nginx-pod-nfs.yaml diff --git a/README.md b/README.md index 71949636d..46d37fcc7 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Please refer to [`nfs.csi.k8s.io` driver parameters](./docs/driver-parameters.md ### Examples - [Basic usage](./deploy/example/README.md) - [fsGroupPolicy](./deploy/example/fsgroup) + - [Volume cloning](./deploy/example/cloning) ### Troubleshooting - [CSI driver troubleshooting guide](./docs/csi-debug.md) diff --git a/deploy/example/cloning/README.md b/deploy/example/cloning/README.md new file mode 100644 index 000000000..921ac5d54 --- /dev/null +++ b/deploy/example/cloning/README.md @@ -0,0 +1,65 @@ +# Volume Cloning Example + +- supported from v4.3.0 + +## Create a Source PVC + +```console +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/storageclass-nfs.yaml +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/pvc-nfs-csi-dynamic.yaml +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nginx-pod-nfs.yaml +``` + +### Check the Source PVC + +```console +$ kubectl exec nginx-nfs -- ls /mnt/nfs +outfile +``` + +## Create a PVC from an existing PVC +> Make sure application is not writing data to source nfs share +```console +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/cloning/pvc-nfs-cloning.yaml +``` +### Check the Creation Status + +```console +$ kubectl describe pvc pvc-nfs-cloning +Name: pvc-nfs-cloning +Namespace: default +StorageClass: nfs-csi +Status: Bound +Volume: pvc-5a00da0e-9afe-40f7-9f52-edabcf28df63 +Labels: +Annotations: kubectl.kubernetes.io/last-applied-configuration: + {"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"pvc-nfs-cloning","namespace":"default"},"spec":{"ac... + pv.kubernetes.io/bind-completed: yes + pv.kubernetes.io/bound-by-controller: yes + volume.beta.kubernetes.io/storage-provisioner: nfs.csi.k8s.io + volume.kubernetes.io/storage-provisioner: nfs.csi.k8s.io +Finalizers: [kubernetes.io/pvc-protection] +Capacity: 10Gi +Access Modes: RWX +VolumeMode: Filesystem +Mounted By: +Events: + Type Reason Age From Message + ---- ------ ---- ---- ------- + Normal ExternalProvisioning 5s persistentvolume-controller waiting for a volume to be created, either by external provisioner "nfs.csi.k8s.io" or manually created by system administrator + Normal Provisioning 5s nfs.csi.k8s.io_aks-nodepool1-34988195-vmss000000_534f1e86-3a71-4ca4-9b83-803c05a44d65 External provisioner is provisioning volume for claim "default/pvc-nfs-cloning" + Normal ProvisioningSucceeded 5s nfs.csi.k8s.io_aks-nodepool1-34988195-vmss000000_534f1e86-3a71-4ca4-9b83-803c05a44d65 Successfully provisioned volume pvc-5a00da0e-9afe-40f7-9f52-edabcf28df63 +``` + +## Restore the PVC into a Pod + +```console +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/cloning/nginx-pod-restored-cloning.yaml +``` + +### Check Sample Data + +```console +$ kubectl exec nginx-nfs-restored-cloning -- ls /mnt/nfs +outfile +``` diff --git a/deploy/example/cloning/nginx-pod-restored-cloning.yaml b/deploy/example/cloning/nginx-pod-restored-cloning.yaml new file mode 100644 index 000000000..bcb033dab --- /dev/null +++ b/deploy/example/cloning/nginx-pod-restored-cloning.yaml @@ -0,0 +1,23 @@ +--- +kind: Pod +apiVersion: v1 +metadata: + name: nginx-nfs-restored-cloning +spec: + nodeSelector: + "kubernetes.io/os": linux + containers: + - image: mcr.microsoft.com/oss/nginx/nginx:1.19.5 + name: nginx-nfs + command: + - "/bin/bash" + - "-c" + - set -euo pipefail; while true; do echo $(date) >> /mnt/nfs/outfile; sleep 1; done + volumeMounts: + - name: persistent-storage + mountPath: "/mnt/nfs" + readOnly: false + volumes: + - name: persistent-storage + persistentVolumeClaim: + claimName: pvc-nfs-cloning diff --git a/deploy/example/pvc-volume-clone.yaml b/deploy/example/cloning/pvc-nfs-cloning.yaml similarity index 91% rename from deploy/example/pvc-volume-clone.yaml rename to deploy/example/cloning/pvc-nfs-cloning.yaml index 5b1575f34..ddb9d88b3 100644 --- a/deploy/example/pvc-volume-clone.yaml +++ b/deploy/example/cloning/pvc-nfs-cloning.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: pvc-nfs-clone + name: pvc-nfs-cloning namespace: default spec: accessModes: diff --git a/deploy/example/nginx-pod-nfs.yaml b/deploy/example/nginx-pod-nfs.yaml new file mode 100644 index 000000000..f46f8d648 --- /dev/null +++ b/deploy/example/nginx-pod-nfs.yaml @@ -0,0 +1,23 @@ +--- +kind: Pod +apiVersion: v1 +metadata: + name: nginx-nfs +spec: + nodeSelector: + "kubernetes.io/os": linux + containers: + - image: mcr.microsoft.com/oss/nginx/nginx:1.19.5 + name: nginx-nfs + command: + - "/bin/bash" + - "-c" + - set -euo pipefail; while true; do echo $(date) >> /mnt/nfs/outfile; sleep 1; done + volumeMounts: + - name: persistent-storage + mountPath: "/mnt/nfs" + readOnly: false + volumes: + - name: persistent-storage + persistentVolumeClaim: + claimName: pvc-nfs-dynamic diff --git a/hack/verify-yamllint.sh b/hack/verify-yamllint.sh index ff78da3c6..c69855aa6 100755 --- a/hack/verify-yamllint.sh +++ b/hack/verify-yamllint.sh @@ -29,7 +29,7 @@ if [[ "${deployDirNum}" != "${helmDirNum}" ]]; then exit 1 fi -for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/nfs-provisioner/*.yaml" +for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/nfs-provisioner/*.yaml" "deploy/example/cloning/*.yaml" do echo "checking yamllint under path: $path ..." yamllint -f parsable $path | grep -v "line too long" > $LOG