Skip to content

Commit 644b21e

Browse files
authored
Merge pull request #264 from hossainemruz/snapshot-guide
Improve VolumeSnapshot guide
2 parents 7a362c6 + 9a59b1b commit 644b21e

File tree

7 files changed

+128
-21
lines changed

7 files changed

+128
-21
lines changed

docs/kubernetes/user-guides/snapshots.md

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
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
8+
69
```
710
$ PROJECT=your-project-here # GCP project
811
$ GCE_PD_SA_NAME=my-gce-pd-csi-sa # Name of the service account to create
@@ -11,6 +14,7 @@ $ ./deploy/setup-project.sh
1114
```
1215

1316
2. Deploy driver to Kubernetes Cluster
17+
1418
```
1519
$ GCE_PD_SA_DIR=/my/safe/credentials/directory # Directory to get the service account key
1620
$ GCE_PD_DRIVER_VERSION=alpha # Driver version to deploy
@@ -19,33 +23,89 @@ $ ./deploy/kubernetes/deploy-driver.sh
1923

2024
### Snapshot Example
2125

22-
1. Create example Default Snapshot Class
26+
**Create Storage Class:**
27+
28+
If you haven't created a `StorageClass` yet, create one first:
29+
30+
```console
31+
kubectl apply -f ./examples/kubernetes/demo-zonal-sc.yaml
2332
```
24-
$ kubectl create -f ./examples/kubernetes/demo-defaultsnapshotclass.yaml
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
2744
```
28-
$ kubectl create -f ./examples/kubernetes/demo-snapshot.yaml
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. This pod will create a file `sample-file.txt` in `/demo/data` directory.
49+
50+
```console
51+
kubectl create -f ./examples/kubernetes/snapshot/source_pod.yaml
52+
```
53+
54+
Check if the file has been created successfully:
55+
56+
```console
57+
$ kubectl exec source-pod -- ls /demo/data/
58+
lost+found
59+
sample-file.txt
2960
```
30-
3. Verify Snapshot is created and is ready to use
61+
62+
**Create a snapshot of the source PVC:**
63+
64+
```console
65+
kubectl create -f ./examples/kubernetes/snapshot/snapshot.yaml
3166
```
32-
$ k get volumesnapshots demo-snapshot-podpvc -o yaml
67+
68+
**Verify Snapshot has been created and it is ready to use:**
69+
70+
```console
71+
$ kubectl get volumesnapshot snapshot-source-pvc -o yaml
3372
apiVersion: snapshot.storage.k8s.io/v1alpha1
3473
kind: VolumeSnapshot
3574
metadata:
36-
creationTimestamp: 2018-10-05T16:59:26Z
37-
generation: 1
38-
name: demo-snapshot-podpvc
75+
...
76+
name: snapshot-source-pvc
3977
namespace: default
40-
41-
...
42-
78+
...
79+
spec:
80+
snapshotClassName: default-snapshot-class
81+
snapshotContentName: snapcontent-b408076b-720b-11e9-b9e3-42010a800014
82+
...
4383
status:
44-
creationTime: 2018-10-05T16:59:27Z
45-
ready: true
84+
creationTime: "2019-05-09T03:37:01Z"
85+
readyToUse: true
4686
restoreSize: 6Gi
87+
```
88+
89+
**Restore the Snapshot into a new PVC:**
4790

91+
Create a new PVC. Specify `spec.dataSource` section to restore from VolumeSnapshot `snapshot-source-pvc`.
92+
93+
```console
94+
kubectl create -f ./examples/kubernetes/snapshot/restored_pvc.yaml
4895
```
49-
4. Create a new volume from the snapshot
96+
97+
**Verify sample data has been restored:**
98+
99+
Create a sample pod with the restored PVC:
100+
101+
```console
102+
kubectl create -f ./examples/kubernetes/snapshot/restored_pod.yaml
103+
```
104+
105+
Check data has been restored in `/demo/data` directory:
106+
107+
```console
108+
$ kubectl exec restored-pod -- ls /demo/data/
109+
lost+found
110+
sample-file.txt
50111
```
51-
$ kubectl create -f ./examples/kubernetes/demo-restore-snapshot.yaml
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,7 +1,7 @@
11
kind: PersistentVolumeClaim
22
apiVersion: v1
33
metadata:
4-
name: restore-snapshot
4+
name: restored-pvc
55
spec:
66
accessModes:
77
- ReadWriteOnce
@@ -11,5 +11,5 @@ spec:
1111
storage: 6Gi
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: source-pod
5+
spec:
6+
containers:
7+
- name: busybox
8+
image: busybox
9+
command: ["/bin/sh", "-c"]
10+
args: ["touch /demo/data/sample-file.txt && sleep 3000"]
11+
volumeMounts:
12+
- name: source-data
13+
mountPath: /demo/data
14+
volumes:
15+
- name: source-data
16+
persistentVolumeClaim:
17+
claimName: source-pvc
18+
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: 6Gi

0 commit comments

Comments
 (0)