Skip to content

Commit 3180e18

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 3180e18

File tree

6 files changed

+181
-13
lines changed

6 files changed

+181
-13
lines changed

README.md

+147-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,143 @@ Events: <none>
188189
```
189190

190191

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

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)