diff --git a/site/content/en/docs/tutorials/volume_snapshots_and_csi.md b/site/content/en/docs/tutorials/volume_snapshots_and_csi.md index e15ae9030d..d66fb7cd52 100644 --- a/site/content/en/docs/tutorials/volume_snapshots_and_csi.md +++ b/site/content/en/docs/tutorials/volume_snapshots_and_csi.md @@ -15,7 +15,7 @@ This tutorial explains how to set up the CSI Hostpath Driver in minikube and cre - latest version of minikube -## Tutorial +## What you’ll need Support for volume snapshots in minikube is provided through the `volumesnapshots` addon. This addon provisions the required CRDs and deploys the Volume Snapshot Controller. It is disabled by default. @@ -44,3 +44,136 @@ name `hostpath.csi.k8s.io`. Use this wherever necessary (e.g. snapshot class def Once both addons are enabled, you can create persistent volumes and snapshots using standard ways (for a quick test of volume snapshots, you can find some example yaml files along with a step-by-step [here](https://kubernetes-csi.github.io/docs/snapshot-restore-feature.html)). The driver stores all persistent volumes in the `/var/lib/csi-hostpath-data/` directory of minikube's host. + +## Tutorial + +In this tutorial, you use `volumesnapshots` addon(1) and `csi-hostpath-driver` addon(2a). + +

1Start your cluster

+ +```shell +minikube start +``` + +

2Enable addons

+ +Enable `volumesnapshots` and `csi-hostpath-driver` addons: + +```shell +minikube addons enable volumesnapshots +minikube addons enable csi-hostpath-driver +``` + +

3Register volume snapshot class

+ +Before creating volume snapshot, you have to register [Volume Snapshot Classes](https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/) to your cluster. +Here is an example `VolumeSnapshotClass` config to register: + +```yaml +# snapshotclass.yaml +apiVersion: snapshot.storage.k8s.io/v1beta1 +kind: VolumeSnapshotClass +metadata: + name: csi-hostpath-snapclass +driver: hostpath.csi.k8s.io #csi-hostpath +deletionPolicy: Delete +``` + +```shell +kubectl apply -f snapshotclass.yaml +``` + +

4Prepare persistent volume

+ +Create persistent volume claim to create persistent volume dynamically: + +```yaml +# example-pvc.yaml +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: csi-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: csi-hostpath-sc +``` + +```shell +kubectl apply -f example-pvc.yaml +``` + +You can confirm that persistent volume is created by the following command: + +```shell +kubectl get pv +NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE +pvc-388c33e2-de56-475c-8dfd-4990d5f7a640 1Gi RWO Delete Bound default/csi-pvc csi-hostpath-sc 60s +``` + +

5Take a volume snapshot

+ +You can take a volume snapshot for persistent volume claim: + +```yaml +# example-csi-snapshot.yaml +apiVersion: snapshot.storage.k8s.io/v1beta1 +kind: VolumeSnapshot +metadata: + name: snapshot-demo +spec: + volumeSnapshotClassName: csi-hostpath-snapclass + source: + persistentVolumeClaimName: csi-pvc +``` + +```shell +kubectl apply -f example-csi-snapshot.yaml +``` + +You could get volume snapshot. You can confirm your volume snapshot by the following command: + +```shell +kubectl get volumesnapshot +NAME AGE +snapshot-demo 2m19s +``` + +

6Restore from volume snapshot

+ +You can restore persistent volume from your volume snapshot: + +```yaml +# example-csi-restore.yaml +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: csi-pvc-restore +spec: + storageClassName: csi-hostpath-sc + dataSource: + name: snapshot-demo + kind: VolumeSnapshot + apiGroup: snapshot.storage.k8s.io + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +``` + +```shell +kubectl apply -f example-csi-restore.yaml +``` + +You can confirm that persistent volume claim is created from `VolumeSnapshot`: + +```shell +kubectl get pvc +NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE +csi-pvc Bound pvc-388c33e2-de56-475c-8dfd-4990d5f7a640 1Gi RWO csi-hostpath-sc 23m +csi-pvc-restore Bound pvc-496bab30-9bd6-4abb-94e9-d2e9e1c8f210 1Gi RWO csi-hostpath-sc 26s +```