1
1
# Kubernetes Snapshots User Guide (Alpha)
2
2
3
+ > ** Attention:** VolumeSnapshot is an alpha feature. Make sure you have enabled it in Kubernetes API server using ` --feature-gates=VolumeSnapshotDataSource=true ` flag.
4
+
3
5
### Install Driver with alpha snapshot feature
4
6
5
7
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
19
21
20
22
### Snapshot Example
21
23
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
23
30
```
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
25
38
```
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
27
58
```
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
29
66
```
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
31
72
```
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
33
78
apiVersion: snapshot.storage.k8s.io/v1alpha1
34
79
kind: VolumeSnapshot
35
80
metadata:
36
- creationTimestamp: 2018-10-05T16:59:26Z
37
- generation: 1
38
- name: demo-snapshot-podpvc
81
+ ...
82
+ name: snapshot-source-pvc
39
83
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
+ ```
40
99
41
- ...
100
+ ** Restore the Snapshot into a new PVC: **
42
101
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 ` .
47
103
104
+ ``` console
105
+ kubectl create -f ./examples/kubernetes/snapshot/restored_pvc.yaml
48
106
```
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
50
122
```
51
- $ kubectl create -f ./examples/kubernetes/demo-restore-snapshot.yaml
0 commit comments