Skip to content

Commit

Permalink
Merge pull request #77 from wnxn/restore-volume
Browse files Browse the repository at this point in the history
restore volume from snapshot
  • Loading branch information
Wiley Wang authored Jul 5, 2019
2 parents 3b5a2be + 9666c5d commit c4eb096
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 72 deletions.
2 changes: 1 addition & 1 deletion deploy/disk/example/snapshot/deploy-viewer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ spec:
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: restore-from-snap
claimName: pvc-snap-2
readOnly: false

2 changes: 1 addition & 1 deletion deploy/disk/example/snapshot/deploy-writer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ spec:
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: pvc-for-snap
claimName: pvc-snap-1
readOnly: false

2 changes: 1 addition & 1 deletion deploy/disk/example/snapshot/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-for-snap
name: pvc-snap-1
spec:
storageClassName: csi-qingcloud
accessModes:
Expand Down
4 changes: 2 additions & 2 deletions deploy/disk/example/snapshot/restore-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: restore-from-snap
name: pvc-snap-2
spec:
storageClassName: csi-qingcloud
dataSource:
name: pvc-for-snap
name: snap-1
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
Expand Down
4 changes: 2 additions & 2 deletions deploy/disk/example/snapshot/volume-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshot
metadata:
name: snap-test
name: snap-1
spec:
snapshotClassName: csi-qingcloud
source:
name: pvc-for-snap
name: pvc-snap-1
kind: PersistentVolumeClaim
6 changes: 3 additions & 3 deletions deploy/disk/example/volume/sc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ metadata:
name: csi-qingcloud
provisioner: disk.csi.qingcloud.com
parameters:
type: "2"
type: "200"
maxSize: "5000"
minSize: "100"
stepSize: "50"
minSize: "10"
stepSize: "10"
fsType: "ext4"
replica: "2"
reclaimPolicy: Delete
Expand Down
112 changes: 112 additions & 0 deletions docs/snapshot-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 快照
快照功能包括创建和删除快照,从快照恢复存储卷功能。示例 YAML 文件在 https://github.com/yunify/qingcloud-csi/tree/master/deploy/disk/example/snapshot 内。

### 准备工作
- Kubernetes 1.14+ 集群
- 在 apiserver, controller-manager 的 `feature-gate` 增加 `VolumeSnapshotDataSource=true`
- 按照 QingCloud CSI 存储插件
- 配置了 QingCloud CSI storageclass
#### 创建带数据的存储卷 `pvc-snap-1`
- 创建存储卷
```
$ kubectl create -f pvc.yaml
persistentvolumeclaim/pvc-snap-1 created
```
- 检查存储卷
```
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-snap-1 Bound pvc-28090960-9eeb-11e9-9a6a-5254ef68c8c1 20Gi RWO csi-qingcloud 37s
```
- 向存储卷写数据
```
$ kubectl create -f deploy-writer.yaml
deployment.apps/fio created
$ kubectl get po
NAME READY STATUS RESTARTS AGE
fio-645b5d6499-8tc7p 1/1 Running 0 23s
$ kubectl exec -ti fio-645b5d6499-8tc7p /bin/bash
root@fio-645b5d6499-8tc7p:/# cd root
root@fio-645b5d6499-8tc7p:/# ./start-test.sh
crtl+c (停止写数据)
root@fio-645b5d6499-8tc7p:/# ls -lh /mnt
total 20G
drwx------ 2 root root 16K Jul 5 06:09 lost+found
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.0.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.1.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.2.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.3.0
-rw-r--r-- 1 root root 10G Jul 5 06:10 seq-write.0.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 seq-write.1.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 seq-write.2.0
-rw-r--r-- 1 root root 9.6G Jul 5 06:10 seq-write.3.0
```

## 创建快照
每个 Kubernetes 快照对应于一个 QingCloud 全量备份,请确保有足够全量备份链配额。

### 创建快照类型
```
$ kubectl create -f snapshot-class.yaml
volumesnapshotclass.snapshot.storage.k8s.io/csi-qingcloud created
$ kubectl get volumesnapshotclass
NAME AGE
csi-qingcloud 16s
```

### 创建快照
```
$ kubectl create -f volume-snapshot.yaml
volumesnapshot.snapshot.storage.k8s.io/snap-1 created
$ kubectl get volumesnapshot
NAME AGE
snap-1 91s
```

## 从快照恢复存储卷
### 恢复存储卷 `pvc-snap-2`
```
$ kubectl create -f restore-pvc.yaml
persistentvolumeclaim/pvc-snap-2 created
```

```
$ kubectl get pvc pvc-snap-2
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-snap-2 Bound pvc-b8a05427-9eef-11e9-9a6a-5254ef68c8c1 20Gi RWO csi-qingcloud 52s
```

### 检查存储卷数据
从快照恢复的存储卷 `pvc-snap-2` 与在创建快照时的 `pvc-snap-1` 内容应一致。

```
$ kubectl create -f deploy-viewer.yaml
deployment.apps/nginx created
$ kubectl get po |grep nginx
nginx-7b98f8c4d4-fmjzf 1/1 Running 0 3m6s
$ kubectl exec -ti nginx-7b98f8c4d4-fmjzf /bin/bash
root@nginx-7b98f8c4d4-fmjzf:/# ls /mnt -lh
total 20G
drwx------ 2 root root 16K Jul 5 06:09 lost+found
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.0.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.1.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.2.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 rand-write.3.0
-rw-r--r-- 1 root root 10G Jul 5 06:10 seq-write.0.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 seq-write.1.0
-rw-r--r-- 1 root root 0 Jul 5 06:10 seq-write.2.0
-rw-r--r-- 1 root root 9.6G Jul 5 06:10 seq-write.3.0
```

## 删除快照

```
$ kubectl delete volumesnapshot snap-1
volumesnapshot.snapshot.storage.k8s.io "snap-1" deleted
```
Loading

0 comments on commit c4eb096

Please sign in to comment.