Skip to content

Commit b49cd5f

Browse files
author
hossainemruz
committed
Improve VolumeSnapshot guide
1 parent 1778a00 commit b49cd5f

File tree

9 files changed

+158
-22
lines changed

9 files changed

+158
-22
lines changed

docs/kubernetes/user-guides/snapshots.md

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Kubernetes Snapshots User Guide (Alpha)
22

3+
>**Attention:** VolumeSnapshot is an alpha feature. Make sure you have enabled it in Kubernetes API server using `--feature-gates=VolumeSnapshotDataSource=true` flag.
4+
35
### Install Driver with alpha snapshot feature
46

57
1. [One-time per project] Create GCP service account for the CSI driver and set required roles
@@ -19,33 +21,102 @@ $ ./deploy/kubernetes/deploy-driver.sh
1921

2022
### Snapshot Example
2123

22-
1. Create example Default Snapshot Class
24+
**Create Storage Class:**
25+
26+
If you haven't created a `StorageClass` yet, create one first:
27+
28+
```console
29+
kubectl apply -f ./examples/kubernetes/snapshot/storageclass.yaml
2330
```
24-
$ kubectl create -f ./examples/kubernetes/demo-defaultsnapshotclass.yaml
31+
32+
For more advance `StorageClass` configuration, please see [Kubernetes Basic User Guide](/docs/kubernetes/user-guides/basic.md).
33+
34+
**Create Default VolumeSnapshotClass:**
35+
36+
```console
37+
kubectl create -f ./examples/kubernetes/snapshot/default_volumesnapshotclass.yaml
2538
```
26-
2. Create a snapshot of the PVC created in above example
39+
40+
**Create source PVC:**
41+
42+
```console
43+
kubectl create -f ./examples/kubernetes/snapshot/source_pvc.yaml
44+
```
45+
46+
**Generate sample data:**
47+
48+
Create a sample pod with the source PVC. The source PVC is mounted into `/demo/data` directory of this pod.
49+
50+
```console
51+
kubectl create -f ./examples/kubernetes/snapshot/source_pod.yaml
52+
```
53+
54+
Now, let's create a file inside `/demo/data` directory:
55+
56+
```console
57+
kubectl exec source-pod -- touch /demo/data/sample-file.txt
2758
```
28-
$ kubectl create -f ./examples/kubernetes/demo-snapshot.yaml
59+
60+
Check if the file has been created successfully:
61+
62+
```console
63+
$ kubectl exec source-pod -- ls /demo/data/
64+
lost+found
65+
sample-file.txt
2966
```
30-
3. Verify Snapshot is created and is ready to use
67+
68+
**Create a snapshot of the source PVC:**
69+
70+
```console
71+
kubectl create -f ./examples/kubernetes/snapshot/snapshot.yaml
3172
```
32-
$ k get volumesnapshots demo-snapshot-podpvc -o yaml
73+
74+
**Verify Snapshot has been created and it is ready to use:**
75+
76+
```console
77+
$ kubectl get volumesnapshot snapshot-source-pvc -o yaml
3378
apiVersion: snapshot.storage.k8s.io/v1alpha1
3479
kind: VolumeSnapshot
3580
metadata:
36-
creationTimestamp: 2018-10-05T16:59:26Z
37-
generation: 1
38-
name: demo-snapshot-podpvc
81+
...
82+
name: snapshot-source-pvc
3983
namespace: default
84+
resourceVersion: "15485"
85+
selfLink: /apis/snapshot.storage.k8s.io/v1alpha1/namespaces/default/volumesnapshots/snapshot-source-pvc
86+
uid: f1b8855d-7007-11e9-8f36-42010a800014
87+
spec:
88+
snapshotClassName: default-snapshot-class
89+
snapshotContentName: snapcontent-f1b8855d-7007-11e9-8f36-42010a800014
90+
source:
91+
apiGroup: null
92+
kind: PersistentVolumeClaim
93+
name: source-pvc
94+
status:
95+
creationTime: "2019-05-06T14:05:04Z"
96+
readyToUse: true
97+
restoreSize: 1Gi
98+
```
4099

41-
...
100+
**Restore the Snapshot into a new PVC:**
42101

43-
status:
44-
creationTime: 2018-10-05T16:59:27Z
45-
ready: true
46-
restoreSize: 6Gi
102+
Create a new PVC. Specify `spec.dataSource` section to restore from VolumeSnapshot `snapshot-source-pvc`.
47103

104+
```console
105+
kubectl create -f ./examples/kubernetes/snapshot/restored_pvc.yaml
48106
```
49-
4. Create a new volume from the snapshot
107+
108+
**Verify sample data has been restored:**
109+
110+
Create a sample pod with the restored PVC:
111+
112+
```console
113+
kubectl create -f ./examples/kubernetes/snapshot/restored_pod.yaml
114+
```
115+
116+
Check data has been restored in `/demo/data` directory:
117+
118+
```console
119+
$ kubectl exec restored-pod -- ls /demo/data/
120+
lost+found
121+
sample-file.txt
50122
```
51-
$ kubectl create -f ./examples/kubernetes/demo-restore-snapshot.yaml

examples/kubernetes/demo-pvc.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: PersistentVolumeClaim
2+
apiVersion: v1
3+
metadata:
4+
name: demo-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
volumeMode: Filesystem
9+
storageClassName: csi-gce-pd
10+
resources:
11+
requests:
12+
storage: 50Mi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: restored-pod
5+
spec:
6+
containers:
7+
- name: busybox
8+
image: busybox
9+
args:
10+
- sleep
11+
- "3600"
12+
volumeMounts:
13+
- name: source-data
14+
mountPath: /demo/data
15+
volumes:
16+
- name: source-data
17+
persistentVolumeClaim:
18+
claimName: restored-pvc
19+
readOnly: false
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
kind: PersistentVolumeClaim
22
apiVersion: v1
33
metadata:
4-
name: restore-snapshot
4+
name: restored-pvc
55
spec:
66
accessModes:
77
- ReadWriteOnce
88
storageClassName: csi-gce-pd
99
resources:
1010
requests:
11-
storage: 6Gi
11+
storage: 1Gi
1212
dataSource:
1313
kind: VolumeSnapshot
14-
name: demo-snapshot-podpvc
14+
name: snapshot-source-pvc
1515
apiGroup: snapshot.storage.k8s.io
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
apiVersion: snapshot.storage.k8s.io/v1alpha1
22
kind: VolumeSnapshot
33
metadata:
4-
name: demo-snapshot-podpvc
4+
name: snapshot-source-pvc
55
spec:
66
source:
77
kind: PersistentVolumeClaim
8-
name: podpvc
9-
8+
name: source-pvc
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: source-pod
5+
spec:
6+
containers:
7+
- name: busybox
8+
image: busybox
9+
args:
10+
- sleep
11+
- "3600"
12+
volumeMounts:
13+
- name: source-data
14+
mountPath: /demo/data
15+
volumes:
16+
- name: source-data
17+
persistentVolumeClaim:
18+
claimName: source-pvc
19+
readOnly: false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: PersistentVolumeClaim
2+
apiVersion: v1
3+
metadata:
4+
name: source-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
storageClassName: csi-gce-pd
9+
resources:
10+
requests:
11+
storage: 1Gi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: storage.k8s.io/v1
2+
kind: StorageClass
3+
metadata:
4+
name: csi-gce-pd
5+
provisioner: pd.csi.storage.gke.io

0 commit comments

Comments
 (0)