|
| 1 | +# Openshift Commands to setup Backup Container |
| 2 | + |
| 3 | +## <summary>Example of a Postgres deployment</summary> |
| 4 | + |
| 5 | +The following outlines the deployment of a simple backup of three PostgreSQL databases in the same project namespace, on OCP v4.x. |
| 6 | + |
| 7 | +1. As per OCP4 [docs](https://developer.gov.bc.ca/OCP4-Backup-and-Restore), 25G of the storage class `netapp-file-backup` is the default quota. If this is insufficient, you may [request](https://github.com/BCDevOps/devops-requests/issues/new/choose) more. |
| 8 | + |
| 9 | +2. `git clone https://github.com/BCDevOps/backup-container.git && cd backup-container`. |
| 10 | + |
| 11 | +Create the image. |
| 12 | + |
| 13 | +```bash |
| 14 | +oc -n d83219-tools process -f ./templates/backup/backup-build.yaml | oc -n d83219-tools create -f - |
| 15 | +``` |
| 16 | + |
| 17 | +3. Configure (./config/backup.conf) (listing your database(s), and setting your cron schedule). |
| 18 | + |
| 19 | +```bash |
| 20 | +postgres=restoration-tracker-db-postgresql:5432/restoration-tracker |
| 21 | +# postgres=pawslimesurvey-postgresql:5432/pawslimesurvey |
| 22 | + |
| 23 | +0 1 * * * default ./backup.sh -s |
| 24 | +0 4 * * * default ./backup.sh -s -v all |
| 25 | +``` |
| 26 | + |
| 27 | +4. Configure references to your DB credentials in [backup-deploy.yaml](./openshift/templates/backup/backup-deploy.yaml), replacing the boilerplate `DATABASE_USER` and `DATABASE_PASSWORD` environment variables. |
| 28 | + |
| 29 | +```yaml |
| 30 | + - name: RESTORATION_TRACKER_DB_POSTGRESQL_DEV_DEPLOY_USER |
| 31 | + valueFrom: |
| 32 | + secretKeyRef: |
| 33 | + key: database-admin |
| 34 | + name: '${DATABASE_SECRET_REF}' |
| 35 | + - name: RESTORATION_TRACKER_DB_POSTGRESQL_DEV_DEPLOY_PASSWORD |
| 36 | + valueFrom: |
| 37 | + secretKeyRef: |
| 38 | + key: database-admin-password |
| 39 | + name: '${DATABASE_SECRET_REF}' |
| 40 | + |
| 41 | +... |
| 42 | +- name: DATABASE_SECRET_REF |
| 43 | + displayName: Database Secret Reference |
| 44 | + description: The name of the secret containing the database credentials. |
| 45 | + required: true |
| 46 | + value: restoration-tracker-creds |
| 47 | +``` |
| 48 | +
|
| 49 | +Note that underscores should be used in the environment variable names. |
| 50 | +
|
| 51 | +5. Create your customized `./openshift/backup-deploy.overrides.param` parameter file, if required. |
| 52 | + |
| 53 | +6. Deploy the app; here the example namespace is `d83219-dev` and the app name is `backup-postgres`: |
| 54 | + |
| 55 | +```bash |
| 56 | +oc -n d83219-dev create configmap backup-conf --from-file=./config/backup.conf |
| 57 | +oc -n d83219-dev label configmap backup-conf app=backup-postgres |
| 58 | +
|
| 59 | +oc -n d83219-dev process -f ./templates/backup/backup-deploy.yaml | oc -n d83219-dev create -f - |
| 60 | +``` |
| 61 | + |
| 62 | +To clean up the deployment |
| 63 | + |
| 64 | +```bash |
| 65 | +oc -n d83219-dev delete pvc/backup-postgres-pvc pvc/backup-verification secret/backup-postgres secret/ftp-secret dc/backup-postgres networkpolicy/backup-postgres configmap/backup-conf |
| 66 | +``` |
| 67 | + |
| 68 | +To clean up the image stream and build configuration |
| 69 | + |
| 70 | +```bash |
| 71 | +oc -n d83219-tools delete buildconfig/backup-postgres imagestream/backup-postgres |
| 72 | +``` |
| 73 | + |
| 74 | +### NOTE: User Management Role Binding Required in tools env |
| 75 | +``` |
| 76 | +kind: RoleBinding |
| 77 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 78 | +metadata: |
| 79 | + name: 'system:image-pullers' |
| 80 | + namespace: d83219-tools |
| 81 | + annotations: |
| 82 | + openshift.io/description: >- |
| 83 | + Allows all pods in this namespace to pull images from this namespace. It |
| 84 | + is auto-managed by a controller; remove subjects to disable. |
| 85 | +subjects: |
| 86 | + - kind: Group |
| 87 | + apiGroup: rbac.authorization.k8s.io |
| 88 | + name: 'system:serviceaccounts:d83219-tools' |
| 89 | + - kind: Group |
| 90 | + apiGroup: rbac.authorization.k8s.io |
| 91 | + name: 'system:serviceaccounts:d83219-dev' |
| 92 | + - kind: Group |
| 93 | + apiGroup: rbac.authorization.k8s.io |
| 94 | + name: 'system:serviceaccounts:d83219-test' |
| 95 | + - kind: Group |
| 96 | + apiGroup: rbac.authorization.k8s.io |
| 97 | + name: 'system:serviceaccounts:d83219-prod' |
| 98 | +roleRef: |
| 99 | + apiGroup: rbac.authorization.k8s.io |
| 100 | + kind: ClusterRole |
| 101 | + name: 'system:image-puller' |
| 102 | +``` |
0 commit comments