Skip to content

Add snapshot deployment example #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 147 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand All @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following output probably also needs to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it was updated with one of previous PRs (added snapshotter pod). In current PR I noticed the list in text lacks the snapshotter


```shell
$ kubectl get pods
Expand All @@ -74,19 +75,19 @@ 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
```

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
Expand Down Expand Up @@ -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: <none>
Expand All @@ -188,6 +189,143 @@ Events: <none>
```


## 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: reword as

"Volume snapshot is an alpha feature introduced in Kubernetes v1.12. The Kubernetes feature gate VolumeSnapshotDataSource must be enabled."


>
> $ kubectl get volumesnapshotclass
> ```
> NAME AGE
> csi-hostpath-snapclass 11s
> ```
>
> $ kubectl describe volumesnapshotclass
> ```
> Name: csi-hostpath-snapclass
> Namespace:
> Labels: <none>
> Annotations: <none>
> 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: <none>
> ```

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: <none>
> Annotations: <none>
> 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: <nil>
> Kind: PersistentVolumeClaim
> Name: csi-pvc
> Status:
> Creation Time: 2018-10-03T14:16:45Z
> Ready: true
> Restore Size: 1Gi
> Events: <none>
> ```
>
> $ kubectl describe volumesnapshotcontent
> ```
> Name: snapcontent-f55db632-c716-11e8-8911-000c2967769a
> Namespace:
> Labels: <none>
> Annotations: <none>
> 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: <none>
> ```

## 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:

Expand Down
9 changes: 5 additions & 4 deletions deploy/deploy-hostpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 15 additions & 0 deletions deploy/snapshot/csi-restore.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions deploy/snapshot/csi-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions deploy/snapshotter/csi-hostpath-snapshotclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshotClass
metadata:
name: csi-hostpath-snapclass
snapshotter: csi-hostpath