Skip to content

Commit

Permalink
Merge pull request #218 from leakingtapan/snapshot
Browse files Browse the repository at this point in the history
Merge snapshot to master branch
  • Loading branch information
k8s-ci-robot authored Feb 20, 2019
2 parents b04d99a + 9a19c2b commit b8fa1e6
Show file tree
Hide file tree
Showing 17 changed files with 844 additions and 49 deletions.
62 changes: 62 additions & 0 deletions deploy/kubernetes/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,56 @@ roleRef:

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: external-snapshotter-role
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents"]
verbs: ["create", "get", "list", "watch", "update", "delete"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshots"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["create", "list", "watch", "delete"]

---

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-snapshotter-binding
subjects:
- kind: ServiceAccount
name: csi-controller-sa
namespace: kube-system
roleRef:
kind: ClusterRole
name: external-snapshotter-role
apiGroup: rbac.authorization.k8s.io

---

kind: StatefulSet
apiVersion: apps/v1beta1
metadata:
Expand Down Expand Up @@ -186,6 +236,18 @@ spec:
volumeMounts:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: csi-snapshotter
image: quay.io/k8scsi/csi-snapshotter:v1.0.1
args:
- --csi-address=$(ADDRESS)
- --connection-timeout=15s
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
imagePullPolicy: Always
volumeMounts:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
volumes:
- name: socket-dir
emptyDir: {}
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ There are several optional parameters that could be passed into `CreateVolumeReq

2. Enable the flag `--allow-privileged=true` in the manifest entries of kubelet and kube-apiserver.

3. Add `--feature-gates=CSINodeInfo=true,CSIDriverRegistry=true` in the manifest entries of kubelet and kube-apiserver. This is required to enable topology support of EBS volumes in Kubernetes.
3. Add `--feature-gates=CSINodeInfo=true,CSIDriverRegistry=true,VolumeSnapshotDataSource=true` in the manifest entries of kubelet and kube-apiserver. This is required to enable topology support of EBS volumes in Kubernetes and restoring volumes from snapshots.

4. Install the `CSINodeInfo` CRD on the cluster using the instructions provided here: [Enabling CSINodeInfo](https://kubernetes-csi.github.io/docs/csi-node-info-object.html#enabling-csinodeinfo).

Expand Down
42 changes: 42 additions & 0 deletions examples/kubernetes/snapshot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Volume Snapshots with AWS EBS CSI Driver

## Overview

This driver implements basic volume snapshotting functionality, i.e. it is possible to use it along with the [external
snapshotter](https://github.com/kubernetes-csi/external-snapshotter) sidecar and create snapshots of EBS volumes using
the `VolumeSnapshot` custom resources.

## Prerequisites

1. Kubernetes 1.13+ (CSI 1.0) is required

2. The `VolumeSnapshotDataSource` feature gate of Kubernetes API server and controller manager must be turned on.

## Usage

This directory contains example YAML files to test the feature. First, see the [deployment example](../../../deploy/kubernetes) and [volume scheduling example](../volume_scheduling)
to set up the external provisioner:

### Set up

1. Create the RBAC rules

2. Start the contoller `StatefulSet`

3. Start the node `DaemonSet`

4. Create a `StorageClass` for dynamic provisioning of the AWS CSI volumes

5. Create a `SnapshotClass` to create `VolumeSnapshot`s using the AWS CSI external controller

6. Create a `PersistentVolumeClaim` and a pod using it

### Taking and restoring volume snapshot

7. Create a `VolumeSnapshot` referencing the `PersistentVolumeClaim`; the snapshot creation may take time to finish:
check the `ReadyToUse` attribute of the `VolumeSnapshot` object to find out when a new `PersistentVolume` can be
created from the snapshot

8. To restore a volume from a snapshot use a `PersistentVolumeClaim` referencing the `VolumeSnapshot` in its `dataSource`; see the
[Kubernetes Persistent Volumes documentation](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#volume-snapshot-and-restore-volume-from-snapshot-support)
and the example [restore claim](./restore-claim.yaml)
11 changes: 11 additions & 0 deletions examples/kubernetes/snapshot/claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
resources:
requests:
storage: 4Gi
17 changes: 17 additions & 0 deletions examples/kubernetes/snapshot/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: ebs-claim
15 changes: 15 additions & 0 deletions examples/kubernetes/snapshot/restore-claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-restore-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
resources:
requests:
storage: 2Gi
dataSource:
name: ebs-volume-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
9 changes: 9 additions & 0 deletions examples/kubernetes/snapshot/snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshot
metadata:
name: ebs-volume-snapshot
spec:
snapshotClassName: csi-aws-snapclass
source:
name: ebs-claim
kind: PersistentVolumeClaim
5 changes: 5 additions & 0 deletions examples/kubernetes/snapshot/snapshotclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshotClass
metadata:
name: csi-aws-snapclass
snapshotter: ebs.csi.aws.com
6 changes: 6 additions & 0 deletions examples/kubernetes/snapshot/storageclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-sc
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff // indirect
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.2.0
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/google/go-cmp v0.2.0 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
Expand Down
Loading

0 comments on commit b8fa1e6

Please sign in to comment.