From 3180e18b3a1be8338cc43d28a834f36abe25cf5f Mon Sep 17 00:00:00 2001 From: Olev Kartau Date: Fri, 29 Mar 2019 15:02:36 +0200 Subject: [PATCH] Add snapshot deployment example Migrated the snapshot example from docs/example to here, with minor updates and cleanup. Corrected misspelled snpshot in deploy file name. --- README.md | 156 +++++++++++++++++- deploy/deploy-hostpath.sh | 9 +- deploy/snapshot/csi-restore.yaml | 15 ++ deploy/snapshot/csi-snapshot.yaml | 9 + .../csi-hostpath-snapshotclass.yaml | 5 + ...ter.yaml => csi-hostpath-snapshotter.yaml} | 0 6 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 deploy/snapshot/csi-restore.yaml create mode 100644 deploy/snapshot/csi-snapshot.yaml create mode 100644 deploy/snapshotter/csi-hostpath-snapshotclass.yaml rename deploy/snapshotter/{csi-hostpath-snpshotter.yaml => csi-hostpath-snapshotter.yaml} (100%) diff --git a/README.md b/README.md index 960ed1a50..c735d1cf9 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,17 @@ This repository hosts the CSI Hostpath driver and all of its build and dependent ## Pre-requisite - Kubernetes cluster -- Running verrsion 1.13 or later +- Running version 1.13 or later - Access to terminal with `kubectl` installed ## Deployment -The easiest way to test the Hostpath driver is to run `deploy/deploy-hostpath.sh` scrip as show: +The easiest way to test the Hostpath driver is to run `deploy/deploy-hostpath.sh` script as shown: ```shell -$ sh deploy/deploy-hostpath.sh +$ deploy/deploy-hostpath.sh ``` -You should see an output similar to the following printed on the terminal showing the application of rbac rules and the result of deploying the hostpath driver, external privisioner and external attacher components: +You should see an output similar to the following printed on the terminal showing the application of rbac rules and the result of deploying the hostpath driver, external provisioner, external attacher and snapshotter components: ```shell applying RBAC rules @@ -38,6 +38,7 @@ statefulset.apps/csi-hostpathplugin created service/csi-hostpath-provisioner created statefulset.apps/csi-hostpath-provisioner created deploying snapshotter +volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass created service/csi-hostpath-snapshotter created statefulset.apps/csi-hostpath-snapshotter created ``` @@ -51,7 +52,7 @@ The [livenessprobe side-container](https://github.com/kubernetes-csi/livenesspro ## Run example application and validate -Next, validate the deployment. First, ensure all expected pods are running properly including the external attacher, provisioner, and the actual hostpath driver plugin: +Next, validate the deployment. First, ensure all expected pods are running properly including the external attacher, provisioner, snapshotter and the actual hostpath driver plugin: ```shell $ kubectl get pods @@ -74,11 +75,11 @@ storageclass.storage.k8s.io/csi-hostpath-sc created Let's validate the components are deployed: ```shell -$> kubectl get pv +$ kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-58d5ec38-03e5-11e9-be51-000c29e88ff1 1Gi RWO Delete Bound default/csi-pvc csi-hostpath-sc 80s -$> kubectl get pvc +$ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE csi-pvc Bound pvc-58d5ec38-03e5-11e9-be51-000c29e88ff1 1Gi RWO csi-hostpath-sc 93s ``` @@ -86,7 +87,7 @@ csi-pvc Bound pvc-58d5ec38-03e5-11e9-be51-000c29e88ff1 1Gi RWO Finally, inspect the application pod `my-csi-app` which mounts a Hostpath volume: ```shell -$> kubectl describe pods/my-csi-app +$ kubectl describe pods/my-csi-app Name: my-csi-app Namespace: default Priority: 0 @@ -165,7 +166,7 @@ Then, use the following command to locate the file. If everything works OK you s An additional way to ensure the driver is working properly is by inspecting the VolumeAttachment API object created that represents the attached volume: ```shell -$> kubectl describe volumeattachment +$ kubectl describe volumeattachment Name: csi-a7515d53b30a1193fd70b822b18181cff1d16422fd922692bce5ea234cb191e9 Namespace: Labels: @@ -188,6 +189,143 @@ Events: ``` +## Snapshot support + +Since volume snapshot is an alpha feature starting in Kubernetes v1.12, you need to enable feature gate called `VolumeSnapshotDataSource` in the Kubernetes. + +> +> $ kubectl get volumesnapshotclass +> ``` +> NAME AGE +> csi-hostpath-snapclass 11s +> ``` +> +> $ kubectl describe volumesnapshotclass +> ``` +> Name: csi-hostpath-snapclass +> Namespace: +> Labels: +> Annotations: +> API Version: snapshot.storage.k8s.io/v1alpha1 +> Kind: VolumeSnapshotClass +> Metadata: +> Creation Timestamp: 2018-10-03T14:15:30Z +> Generation: 1 +> Resource Version: 2418 +> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/volumesnapshotclasses/csi-hostpath-snapclass +> UID: c8f5bc47-c716-11e8-8911-000c2967769a +> Snapshotter: csi-hostpath +> Events: +> ``` + +Use the volume snapshot class to dynamically create a volume snapshot: + +> $ kubectl create -f deploy/snapshot/csi-snapshot.yaml +> ``` +> volumesnapshot.snapshot.storage.k8s.io/new-snapshot-demo created +> ``` +> +> +> $ kubectl get volumesnapshot +> ``` +> NAME AGE +> new-snapshot-demo 12s +> ``` +> +> $ kubectl get volumesnapshotcontent +>``` +> NAME AGE +> snapcontent-f55db632-c716-11e8-8911-000c2967769a 14s +> ``` +> +> $ kubectl describe volumesnapshot +> ``` +> Name: new-snapshot-demo +> Namespace: default +> Labels: +> Annotations: +> API Version: snapshot.storage.k8s.io/v1alpha1 +> Kind: VolumeSnapshot +> Metadata: +> Creation Timestamp: 2018-10-03T14:16:45Z +> Generation: 1 +> Resource Version: 2476 +> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/namespaces/default/volumesnapshots/new-snapshot-demo +> UID: f55db632-c716-11e8-8911-000c2967769a +> Spec: +> Snapshot Class Name: csi-hostpath-snapclass +> Snapshot Content Name: snapcontent-f55db632-c716-11e8-8911-000c2967769a +> Source: +> API Group: +> Kind: PersistentVolumeClaim +> Name: csi-pvc +> Status: +> Creation Time: 2018-10-03T14:16:45Z +> Ready: true +> Restore Size: 1Gi +> Events: +> ``` +> +> $ kubectl describe volumesnapshotcontent +> ``` +> Name: snapcontent-f55db632-c716-11e8-8911-000c2967769a +> Namespace: +> Labels: +> Annotations: +> API Version: snapshot.storage.k8s.io/v1alpha1 +> Kind: VolumeSnapshotContent +> Metadata: +> Creation Timestamp: 2018-10-03T14:16:45Z +> Generation: 1 +> Resource Version: 2474 +> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/volumesnapshotcontents/snapcontent-f55db632-c716-11e8-8911-000c2967769a +> UID: f561411f-c716-11e8-8911-000c2967769a +> Spec: +> Csi Volume Snapshot Source: +> Creation Time: 1538576205471577525 +> Driver: csi-hostpath +> Restore Size: 1073741824 +> Snapshot Handle: f55ff979-c716-11e8-bb16-000c2967769a +> Deletion Policy: Delete +> Persistent Volume Ref: +> API Version: v1 +> Kind: PersistentVolume +> Name: pvc-0571cc14-c714-11e8-8911-000c2967769a +> Resource Version: 1573 +> UID: 0575b966-c714-11e8-8911-000c2967769a +> Snapshot Class Name: csi-hostpath-snapclass +> Volume Snapshot Ref: +> API Version: snapshot.storage.k8s.io/v1alpha1 +> Kind: VolumeSnapshot +> Name: new-snapshot-demo +> Namespace: default +> Resource Version: 2472 +> UID: f55db632-c716-11e8-8911-000c2967769a +> Events: +> ``` + +## Restore volume from snapshot support + +Follow the following example to create a volume from a volume snapshot: + +> $ kubectl create -f deploy/snapshot/csi-restore.yaml +> `persistentvolumeclaim/hpvc-restore created` +> +> $ kubectl get pvc +> ``` +> NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE +> csi-pvc Bound pvc-0571cc14-c714-11e8-8911-000c2967769a 1Gi RWO csi-hostpath-sc 24m +> hpvc-restore Bound pvc-77324684-c717-11e8-8911-000c2967769a 1Gi RWO csi-hostpath-sc 6s +> ``` +> +> $ kubectl get pv +> ``` +> NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE +> pvc-0571cc14-c714-11e8-8911-000c2967769a 1Gi RWO Delete Bound default/csi-pvc csi-hostpath-sc 25m +> pvc-77324684-c717-11e8-8911-000c2967769a 1Gi RWO Delete Bound default/hpvc-restore csi-hostpath-sc 33s +> ``` + + ## Building the binaries If you want to build the driver yourself, you can do so with the following command from the root directory: diff --git a/deploy/deploy-hostpath.sh b/deploy/deploy-hostpath.sh index dcaee82fd..cd33f62f7 100755 --- a/deploy/deploy-hostpath.sh +++ b/deploy/deploy-hostpath.sh @@ -23,7 +23,7 @@ BASE_DIR=$(dirname "$0") K8S_RELEASE=${K8S_RELEASE:-"release-1.13"} PROVISIONER_RELEASE=${PROVISIONER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner)} ATTACHER_RELEASE=${ATTACHER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher)} -SNAPSHOTTER_RELEASE=${SNAPSHOTTER_RELEASE:-$(image_version "${BASE_DIR}/snapshotter/csi-hostpath-snpshotter.yaml" csi-snapshotter)} +SNAPSHOTTER_RELEASE=${SNAPSHOTTER_RELEASE:-$(image_version "${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml" csi-snapshotter)} INSTALL_CRD=${INSTALL_CRD:-"false"} # apply CSIDriver and CSINodeInfo API objects @@ -43,6 +43,7 @@ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snaps echo "deploying hostpath components" kubectl apply -f ${BASE_DIR}/hostpath -# deploy snapshotter -echo "deploying snapshotter" -kubectl apply -f ${BASE_DIR}/snapshotter +# deploy snapshotter and snapshotclass +echo "deploying snapshotter and snapshotclass" +kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml +kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotclass.yaml diff --git a/deploy/snapshot/csi-restore.yaml b/deploy/snapshot/csi-restore.yaml new file mode 100644 index 000000000..c28d1eedd --- /dev/null +++ b/deploy/snapshot/csi-restore.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: hpvc-restore +spec: + storageClassName: csi-hostpath-sc + dataSource: + name: new-snapshot-demo + kind: VolumeSnapshot + apiGroup: snapshot.storage.k8s.io + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/deploy/snapshot/csi-snapshot.yaml b/deploy/snapshot/csi-snapshot.yaml new file mode 100644 index 000000000..10ae3bcb5 --- /dev/null +++ b/deploy/snapshot/csi-snapshot.yaml @@ -0,0 +1,9 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshot +metadata: + name: new-snapshot-demo +spec: + snapshotClassName: csi-hostpath-snapclass + source: + name: csi-pvc + kind: PersistentVolumeClaim diff --git a/deploy/snapshotter/csi-hostpath-snapshotclass.yaml b/deploy/snapshotter/csi-hostpath-snapshotclass.yaml new file mode 100644 index 000000000..dfa34df56 --- /dev/null +++ b/deploy/snapshotter/csi-hostpath-snapshotclass.yaml @@ -0,0 +1,5 @@ +apiVersion: snapshot.storage.k8s.io/v1alpha1 +kind: VolumeSnapshotClass +metadata: + name: csi-hostpath-snapclass +snapshotter: csi-hostpath diff --git a/deploy/snapshotter/csi-hostpath-snpshotter.yaml b/deploy/snapshotter/csi-hostpath-snapshotter.yaml similarity index 100% rename from deploy/snapshotter/csi-hostpath-snpshotter.yaml rename to deploy/snapshotter/csi-hostpath-snapshotter.yaml