Skip to content

Commit 13e1067

Browse files
committed
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.
1 parent b714fc4 commit 13e1067

File tree

6 files changed

+179
-13
lines changed

6 files changed

+179
-13
lines changed

README.md

+145-9
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ This repository hosts the CSI Hostpath driver and all of its build and dependent
44

55
## Pre-requisite
66
- Kubernetes cluster
7-
- Running verrsion 1.13 or later
7+
- Running version 1.13 or later
88
- Access to terminal with `kubectl` installed
99

1010
## Deployment
11-
The easiest way to test the Hostpath driver is to run `deploy/deploy-hostpath.sh` scrip as show:
11+
The easiest way to test the Hostpath driver is to run `deploy/deploy-hostpath.sh` script as shown:
1212

1313
```shell
14-
$ sh deploy/deploy-hostpath.sh
14+
$ deploy/deploy-hostpath.sh
1515
```
1616

17-
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:
17+
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:
1818

1919
```shell
2020
applying RBAC rules
@@ -38,6 +38,7 @@ statefulset.apps/csi-hostpathplugin created
3838
service/csi-hostpath-provisioner created
3939
statefulset.apps/csi-hostpath-provisioner created
4040
deploying snapshotter
41+
volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass created
4142
service/csi-hostpath-snapshotter created
4243
statefulset.apps/csi-hostpath-snapshotter created
4344
```
@@ -51,7 +52,7 @@ The [livenessprobe side-container](https://github.com/kubernetes-csi/livenesspro
5152

5253
## Run example application and validate
5354

54-
Next, validate the deployment. First, ensure all expected pods are running properly including the external attacher, provisioner, and the actual hostpath driver plugin:
55+
Next, validate the deployment. First, ensure all expected pods are running properly including the external attacher, provisioner, snapshotter and the actual hostpath driver plugin:
5556

5657
```shell
5758
$ kubectl get pods
@@ -74,19 +75,19 @@ storageclass.storage.k8s.io/csi-hostpath-sc created
7475
Let's validate the components are deployed:
7576

7677
```shell
77-
$> kubectl get pv
78+
$ kubectl get pv
7879
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
7980
pvc-58d5ec38-03e5-11e9-be51-000c29e88ff1 1Gi RWO Delete Bound default/csi-pvc csi-hostpath-sc 80s
8081

81-
$> kubectl get pvc
82+
$ kubectl get pvc
8283
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
8384
csi-pvc Bound pvc-58d5ec38-03e5-11e9-be51-000c29e88ff1 1Gi RWO csi-hostpath-sc 93s
8485
```
8586

8687
Finally, inspect the application pod `my-csi-app` which mounts a Hostpath volume:
8788

8889
```shell
89-
$> kubectl describe pods/my-csi-app
90+
$ kubectl describe pods/my-csi-app
9091
Name: my-csi-app
9192
Namespace: default
9293
Priority: 0
@@ -165,7 +166,7 @@ Then, use the following command to locate the file. If everything works OK you s
165166
An additional way to ensure the driver is working properly is by inspecting the VolumeAttachment API object created that represents the attached volume:
166167

167168
```shell
168-
$> kubectl describe volumeattachment
169+
$ kubectl describe volumeattachment
169170
Name: csi-a7515d53b30a1193fd70b822b18181cff1d16422fd922692bce5ea234cb191e9
170171
Namespace:
171172
Labels: <none>
@@ -188,6 +189,141 @@ Events: <none>
188189
```
189190

190191

192+
## Snapshot support
193+
194+
Since volume snapshot is an alpha feature in Kubernetes v1.12 and v1.13, you need to enable feature gate called `VolumeSnapshotDataSource` in the Kubernetes API server binary.
195+
196+
>
197+
> $ kubectl get volumesnapshotclass
198+
> ```
199+
> NAME AGE
200+
> csi-hostpath-snapclass 11s
201+
> ```
202+
>
203+
> $ kubectl describe volumesnapshotclass
204+
> ```
205+
> Name: csi-hostpath-snapclass
206+
> Namespace:
207+
> Labels: <none>
208+
> Annotations: <none>
209+
> API Version: snapshot.storage.k8s.io/v1alpha1
210+
> Kind: VolumeSnapshotClass
211+
> Metadata:
212+
> Creation Timestamp: 2018-10-03T14:15:30Z
213+
> Generation: 1
214+
> Resource Version: 2418
215+
> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/volumesnapshotclasses/csi-hostpath-snapclass
216+
> UID: c8f5bc47-c716-11e8-8911-000c2967769a
217+
> Snapshotter: csi-hostpath
218+
> Events: <none>
219+
> ```
220+
221+
Use the volume snapshot class to dynamically create a volume snapshot:
222+
223+
> $ kubectl create -f deploy/snapshot/csi-snapshot.yaml
224+
> `volumesnapshot.snapshot.storage.k8s.io/new-snapshot-demo created`
225+
>
226+
>
227+
> $ kubectl get volumesnapshot
228+
> ```
229+
> NAME AGE
230+
> new-snapshot-demo 12s
231+
> ```
232+
>
233+
> $ kubectl get volumesnapshotcontent
234+
>```
235+
> NAME AGE
236+
> snapcontent-f55db632-c716-11e8-8911-000c2967769a 14s
237+
> ```
238+
>
239+
> $ kubectl describe volumesnapshot
240+
> ```
241+
> Name: new-snapshot-demo
242+
> Namespace: default
243+
> Labels: <none>
244+
> Annotations: <none>
245+
> API Version: snapshot.storage.k8s.io/v1alpha1
246+
> Kind: VolumeSnapshot
247+
> Metadata:
248+
> Creation Timestamp: 2018-10-03T14:16:45Z
249+
> Generation: 1
250+
> Resource Version: 2476
251+
> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/namespaces/default/volumesnapshots/new-snapshot-demo
252+
> UID: f55db632-c716-11e8-8911-000c2967769a
253+
> Spec:
254+
> Snapshot Class Name: csi-hostpath-snapclass
255+
> Snapshot Content Name: snapcontent-f55db632-c716-11e8-8911-000c2967769a
256+
> Source:
257+
> API Group: <nil>
258+
> Kind: PersistentVolumeClaim
259+
> Name: csi-pvc
260+
> Status:
261+
> Creation Time: 2018-10-03T14:16:45Z
262+
> Ready: true
263+
> Restore Size: 1Gi
264+
> Events: <none>
265+
> ```
266+
>
267+
> $ kubectl describe volumesnapshotcontent
268+
> ```
269+
> Name: snapcontent-f55db632-c716-11e8-8911-000c2967769a
270+
> Namespace:
271+
> Labels: <none>
272+
> Annotations: <none>
273+
> API Version: snapshot.storage.k8s.io/v1alpha1
274+
> Kind: VolumeSnapshotContent
275+
> Metadata:
276+
> Creation Timestamp: 2018-10-03T14:16:45Z
277+
> Generation: 1
278+
> Resource Version: 2474
279+
> Self Link: /apis/snapshot.storage.k8s.io/v1alpha1/volumesnapshotcontents/snapcontent-f55db632-c716-11e8-8911-000c2967769a
280+
> UID: f561411f-c716-11e8-8911-000c2967769a
281+
> Spec:
282+
> Csi Volume Snapshot Source:
283+
> Creation Time: 1538576205471577525
284+
> Driver: csi-hostpath
285+
> Restore Size: 1073741824
286+
> Snapshot Handle: f55ff979-c716-11e8-bb16-000c2967769a
287+
> Deletion Policy: Delete
288+
> Persistent Volume Ref:
289+
> API Version: v1
290+
> Kind: PersistentVolume
291+
> Name: pvc-0571cc14-c714-11e8-8911-000c2967769a
292+
> Resource Version: 1573
293+
> UID: 0575b966-c714-11e8-8911-000c2967769a
294+
> Snapshot Class Name: csi-hostpath-snapclass
295+
> Volume Snapshot Ref:
296+
> API Version: snapshot.storage.k8s.io/v1alpha1
297+
> Kind: VolumeSnapshot
298+
> Name: new-snapshot-demo
299+
> Namespace: default
300+
> Resource Version: 2472
301+
> UID: f55db632-c716-11e8-8911-000c2967769a
302+
> Events: <none>
303+
> ```
304+
305+
## Restore volume from snapshot support
306+
307+
Follow the following example to create a volume from a volume snapshot:
308+
309+
> $ kubectl create -f deploy/snapshot/csi-restore.yaml
310+
> `persistentvolumeclaim/hpvc-restore created`
311+
>
312+
> $ kubectl get pvc
313+
> ```
314+
> NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
315+
> csi-pvc Bound pvc-0571cc14-c714-11e8-8911-000c2967769a 1Gi RWO csi-hostpath-sc 24m
316+
> hpvc-restore Bound pvc-77324684-c717-11e8-8911-000c2967769a 1Gi RWO csi-hostpath-sc 6s
317+
> ```
318+
>
319+
> $ kubectl get pv
320+
> ```
321+
> NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
322+
> pvc-0571cc14-c714-11e8-8911-000c2967769a 1Gi RWO Delete Bound default/csi-pvc csi-hostpath-sc 25m
323+
> pvc-77324684-c717-11e8-8911-000c2967769a 1Gi RWO Delete Bound default/hpvc-restore csi-hostpath-sc 33s
324+
> ```
325+
326+
191327
## Building the binaries
192328
If you want to build the driver yourself, you can do so with the following command from the root directory:
193329

deploy/deploy-hostpath.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BASE_DIR=$(dirname "$0")
2323
K8S_RELEASE=${K8S_RELEASE:-"release-1.13"}
2424
PROVISIONER_RELEASE=${PROVISIONER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner)}
2525
ATTACHER_RELEASE=${ATTACHER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher)}
26-
SNAPSHOTTER_RELEASE=${SNAPSHOTTER_RELEASE:-$(image_version "${BASE_DIR}/snapshotter/csi-hostpath-snpshotter.yaml" csi-snapshotter)}
26+
SNAPSHOTTER_RELEASE=${SNAPSHOTTER_RELEASE:-$(image_version "${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml" csi-snapshotter)}
2727
INSTALL_CRD=${INSTALL_CRD:-"false"}
2828

2929
# apply CSIDriver and CSINodeInfo API objects
@@ -43,6 +43,7 @@ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snaps
4343
echo "deploying hostpath components"
4444
kubectl apply -f ${BASE_DIR}/hostpath
4545

46-
# deploy snapshotter
47-
echo "deploying snapshotter"
48-
kubectl apply -f ${BASE_DIR}/snapshotter
46+
# deploy snapshotter and snapshotclass
47+
echo "deploying snapshotter and snapshotclass"
48+
kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml
49+
kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotclass.yaml

deploy/snapshot/csi-restore.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: hpvc-restore
5+
spec:
6+
storageClassName: csi-hostpath-sc
7+
dataSource:
8+
name: new-snapshot-demo
9+
kind: VolumeSnapshot
10+
apiGroup: snapshot.storage.k8s.io
11+
accessModes:
12+
- ReadWriteOnce
13+
resources:
14+
requests:
15+
storage: 1Gi

deploy/snapshot/csi-snapshot.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: snapshot.storage.k8s.io/v1alpha1
2+
kind: VolumeSnapshot
3+
metadata:
4+
name: new-snapshot-demo
5+
spec:
6+
snapshotClassName: csi-hostpath-snapclass
7+
source:
8+
name: csi-pvc
9+
kind: PersistentVolumeClaim
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: snapshot.storage.k8s.io/v1alpha1
2+
kind: VolumeSnapshotClass
3+
metadata:
4+
name: csi-hostpath-snapclass
5+
snapshotter: csi-hostpath

0 commit comments

Comments
 (0)