|
| 1 | +# Backups using Alibaba Cloud Object Storage Service (OSS) |
| 2 | + |
| 3 | +Etcd backup operator backs up the data of an etcd cluster running on Kubernetes to a remote storage such as Alibaba Cloud Object Storage Service (OSS). If it is not deployed yet, please follow the [instructions](walkthrough/backup-operator.md#deploy-etcd-backup-operator) to deploy it, e.g. by running |
| 4 | + |
| 5 | +```sh |
| 6 | +kubectl apply -f example/etcd-backup-operator/deployment.yaml |
| 7 | +``` |
| 8 | + |
| 9 | +## Setup Alibaba Cloud backup account, OSS bucket, and Secret |
| 10 | + |
| 11 | +1. Login [Alibaba Cloud Console](https://www.alibabacloud.com) (or [Aliyun Console](https://www.aliyun.com/) if you are in China) and create your own [AccessKey](https://www.alibabacloud.com/help/doc-detail/29009.htm) which gives you the AccessKeyID (AKID) and AccessKeySecret (AKS). You can optionally create an Object Storage Service ([OSS](https://www.alibabacloud.com/help/doc-detail/31947.htm)) bucket for backups. |
| 12 | +2. Create a secret storing your AKID and AKS in Kubernetes. |
| 13 | + |
| 14 | + ```yaml |
| 15 | +apiVersion: v1 |
| 16 | + kind: Secret |
| 17 | + metadata: |
| 18 | + name: my-oss-credentials |
| 19 | + type: Opaque |
| 20 | + data: |
| 21 | + accessKeyID: <my-access-key-id> |
| 22 | + accessKeySecret: <my-access-key-secret> |
| 23 | + ``` |
| 24 | +
|
| 25 | +3. Create an `EtcdBackup` CR file `etcdbackup.yaml` which uses secret `my-oss-credentials` from the previous step. |
| 26 | +```yaml |
| 27 | +apiVersion: etcd.database.coreos.com/v1beta2 |
| 28 | +kind: EtcdBackup |
| 29 | +metadata: |
| 30 | + name: etcd-cluster-with-oss-backup |
| 31 | +spec: |
| 32 | + backupPolicy: |
| 33 | + ... |
| 34 | + etcdEndpoints: |
| 35 | + - "http://example-etcd-cluster-client:2379" |
| 36 | + storageType: OSS |
| 37 | + oss: |
| 38 | + endpoint: http://oss-cn-hangzhou.aliyuncs.com |
| 39 | + ossSecret: my-oss-credentials |
| 40 | + path: my-etcd-backups-bucket/etcd.backup |
| 41 | +``` |
| 42 | + |
| 43 | +4. Apply yaml file to kubernetes cluster. |
| 44 | +```sh |
| 45 | +kubectl apply -f etcdbackup.yaml |
| 46 | +``` |
| 47 | +5. Check the `status` section of the `EtcdBackup` CR. |
| 48 | +```console |
| 49 | +$ kubectl get EtcdBackup etcd-cluster-with-oss-backup -o yaml |
| 50 | +apiVersion: etcd.database.coreos.com/v1beta2 |
| 51 | +kind: EtcdBackup |
| 52 | +... |
| 53 | +spec: |
| 54 | + oss: |
| 55 | + ossSecret: my-oss-credentials |
| 56 | + path: my-etcd-backups-bucket/etcd.backup |
| 57 | + endpoint: http://oss-cn-hangzhou.aliyuncs.com |
| 58 | + etcdEndpoints: |
| 59 | + - http://example-etcd-cluster-client:2379 |
| 60 | + storageType: OSS |
| 61 | +status: |
| 62 | + etcdRevision: 1 |
| 63 | + etcdVersion: 3.2.13 |
| 64 | + succeeded: true |
| 65 | +``` |
| 66 | + |
| 67 | +6. We should see the backup files from Alibaba Cloud OSS Console. |
| 68 | + |
| 69 | + |
| 70 | +## Restore etcd based on data from OSS. |
| 71 | + |
| 72 | +Etcd restore operator is in charge of restoring etcd cluster from backup. If it is not deployed, please deploy by following command: |
| 73 | + |
| 74 | +```sh |
| 75 | +kubectl apply -f example/etcd-restore-operator/deployment.yaml |
| 76 | +``` |
| 77 | + |
| 78 | +Now kill all the etcd pods to simulate a cluster failure: |
| 79 | + |
| 80 | +```sh |
| 81 | +kubectl delete pod -l app=etcd,etcd_cluster=example-etcd-cluster --force --grace-period=0 |
| 82 | +``` |
| 83 | + |
| 84 | +1. Create an EtcdRestore CR. |
| 85 | +```yaml |
| 86 | +apiVersion: "etcd.database.coreos.com/v1beta2" |
| 87 | +kind: "EtcdRestore" |
| 88 | +metadata: |
| 89 | + # The restore CR name must be the same as spec.etcdCluster.name |
| 90 | + name: example-etcd-cluster |
| 91 | +spec: |
| 92 | + etcdCluster: |
| 93 | + # The namespace is the same as this EtcdRestore CR |
| 94 | + name: example-etcd-cluster |
| 95 | + backupStorageType: OSS |
| 96 | + oss: |
| 97 | + # The format of the path must be: "<oss-bucket-name>/<path-to-backup-file>" |
| 98 | + path: my-etcd-backups-bucket/etcd.backup |
| 99 | + ossSecret: my-oss-credentials |
| 100 | + endpoint: http://oss-cn-hangzhou.aliyuncs.com |
| 101 | +``` |
| 102 | + |
| 103 | +2. Check the `status` section of the `EtcdRestore` CR. |
| 104 | +```sh |
| 105 | +$ kubectl get etcdrestore example-etcd-cluster -o yaml |
| 106 | +apiVersion: etcd.database.coreos.com/v1beta2 |
| 107 | +kind: EtcdRestore |
| 108 | +... |
| 109 | +spec: |
| 110 | + oss: |
| 111 | + ossSecret: my-oss-credentials |
| 112 | + path: my-etcd-backups-bucket/etcd.backup |
| 113 | + endpoint: http://oss-cn-hangzhou.aliyuncs.com |
| 114 | + backupStorageType: OSS |
| 115 | + etcdCluster: |
| 116 | + name: example-etcd-cluster |
| 117 | +status: |
| 118 | + succeeded: true |
| 119 | +``` |
| 120 | + |
| 121 | +3. Verify the `EtcdCluster` CR and restored pods for the restored cluster. |
| 122 | +```sh |
| 123 | +$ kubectl get etcdcluster |
| 124 | +$ kubectl get pods -l app=etcd,etcd_cluster=example-etcd-cluster |
| 125 | +``` |
0 commit comments