From 5a8fbbd8e01a04a7c642c334f1d2f562466afc39 Mon Sep 17 00:00:00 2001 From: Kersten Burkhardt Date: Tue, 24 Oct 2017 22:42:40 +0200 Subject: [PATCH] Added zammad-backup und s3 sync --- kubernetes/10_pvc.yaml | 14 ++++++++ kubernetes/20_configmap_backup.yaml | 7 ++++ kubernetes/30_secret_backup.yaml | 9 +++++ kubernetes/56_statefulset_backup.yaml | 38 ++++++++++++++++++++ kubernetes/60_cronjob_backup.yaml | 51 +++++++++++++++++++++++++++ kubernetes/Readme.md | 18 +++++++++- 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 kubernetes/20_configmap_backup.yaml create mode 100644 kubernetes/30_secret_backup.yaml create mode 100644 kubernetes/56_statefulset_backup.yaml create mode 100644 kubernetes/60_cronjob_backup.yaml diff --git a/kubernetes/10_pvc.yaml b/kubernetes/10_pvc.yaml index acd8d93..59b84fd 100644 --- a/kubernetes/10_pvc.yaml +++ b/kubernetes/10_pvc.yaml @@ -34,6 +34,20 @@ metadata: namespace: zammad annotations: volume.beta.kubernetes.io/storage-class: standard +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 10G +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: zammad-backup + namespace: zammad + annotations: + volume.beta.kubernetes.io/storage-class: standard spec: accessModes: - ReadWriteMany diff --git a/kubernetes/20_configmap_backup.yaml b/kubernetes/20_configmap_backup.yaml new file mode 100644 index 0000000..00e384f --- /dev/null +++ b/kubernetes/20_configmap_backup.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: zammad-backup + namespace: zammad +data: + S3_PATH: s3://BUCKET_NAME/ diff --git a/kubernetes/30_secret_backup.yaml b/kubernetes/30_secret_backup.yaml new file mode 100644 index 0000000..e7ede46 --- /dev/null +++ b/kubernetes/30_secret_backup.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: zammad-backup-s3 + namespace: zammad +type: Opaque +data: + ACCESS_KEY: 'bash ACCESS_KEY | base64' + SECRET_KEY: 'bash SECRET_KEY | base64' \ No newline at end of file diff --git a/kubernetes/56_statefulset_backup.yaml b/kubernetes/56_statefulset_backup.yaml new file mode 100644 index 0000000..9b1ad22 --- /dev/null +++ b/kubernetes/56_statefulset_backup.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: zammad-backup + namespace: zammad + labels: + component: backup + app: zammad +spec: + serviceName: zammad-backup + replicas: 1 + template: + metadata: + labels: + component: backup + app: zammad + spec: + terminationGracePeriodSeconds: 10 + volumes: + - name: zammad-home + persistentVolumeClaim: + claimName: zammad-home + - name: zammad-backup + persistentVolumeClaim: + claimName: zammad-backup + containers: + - name: zammad-backup + image: zammad/zammad-docker-compose:zammad-postgresql + command: + - /usr/local/bin/backup.sh + args: + - zammad-backup + imagePullPolicy: Always + volumeMounts: + - mountPath: /home/zammad + name: zammad-home + - mountPath: /var/tmp/zammad + name: zammad-backup \ No newline at end of file diff --git a/kubernetes/60_cronjob_backup.yaml b/kubernetes/60_cronjob_backup.yaml new file mode 100644 index 0000000..821be48 --- /dev/null +++ b/kubernetes/60_cronjob_backup.yaml @@ -0,0 +1,51 @@ +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + name: zammad-backup + namespace: zammad + labels: + component: cronjob + app: backup +spec: + failedJobsHistoryLimit: 0 + successfulJobsHistoryLimit: 0 + concurrencyPolicy: Forbid + schedule: "0 0 * * *" + jobTemplate: + spec: + template: + metadata: + labels: + component: cronjob + app: backup + spec: + volumes: + - name: zammad-backup + persistentVolumeClaim: + claimName: zammad-backup + containers: + - name: zammad-backup-s3 + imagePullPolicy: Always + image: robbydooo/docker-backup-to-s3 + args: + - "/start.sh" + - "no-cron" + envFrom: + - configMapRef: + name: zammad-backup + env: + - name: ACCESS_KEY + valueFrom: + secretKeyRef: + name: zammad-backup-s3 + key: ACCESS_KEY + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: zammad-backup-s3 + key: SECRET_KEY + volumeMounts: + - mountPath: /data + name: zammad-backup + restartPolicy: OnFailure \ No newline at end of file diff --git a/kubernetes/Readme.md b/kubernetes/Readme.md index 46b4c8d..4526c3d 100644 --- a/kubernetes/Readme.md +++ b/kubernetes/Readme.md @@ -4,4 +4,20 @@ - On every node you need to set `sysctl -w vm.max_map_count=262144` - Change the ingress to your needs. -- Hit `kubectl apply -f ./` and wait till everything is setup. \ No newline at end of file + +## Amazon S3 Backup + +If you want to be synced with a S3 bucket, then just fill the `30_secret_backup.yaml` with your secret and access keys. + +```bash +echo -n "ACCESS_KEY" | base64 +echo -n "SECRET_KEY" | base64 +``` + +Change the bucket path in the `20_configmap_backup.yaml`. + +That's it. + +## Deploy zammad + +Hit `kubectl apply -f ./` and wait till everything is setup. \ No newline at end of file