|
| 1 | +# Upgrading Metabase |
| 2 | + |
| 3 | +Metabase upgrades happen in two phases: validation and release. |
| 4 | + |
| 5 | +## Validation |
| 6 | + |
| 7 | +When Metabase detects a version change, it runs a set of database migrations. In order to prevent this migration from causing an outage, you should validate the new version against the `metabase-test` namespace. There are three steps involved: retrieving a `metabase` database snapshot, restoring the snapshot to the `metabase-test` database, and setting the Docker image tag version. It is important to run the Validation steps below in the `metabase-test` namespace in order to prevent data loss. |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +- Lens (https://k8slens.dev) |
| 12 | +- Restic (https://restic.net) |
| 13 | +- A copy of the secrets for the GCloud service account |
| 14 | + |
| 15 | +### Service Credentials |
| 16 | + |
| 17 | +1. Log into GCloud: `gcloud auth login` |
| 18 | +2. List the clusters you can access: `gcloud container clusters list` |
| 19 | +3. Pull Kubernetes credentials for the `data-infra-apps` cluster to your local machine: `gcloud container clusters get-credentials data-infra-apps --location us-west1` |
| 20 | + |
| 21 | +### Replicating the database |
| 22 | + |
| 23 | +1. Retrieve environment variables for one of the `metabase-test` `postgresql-backup` pods |
| 24 | +2. Set the `GOOGLE_APPLICATION_CREDENTIALS`, `GOOGLE_PROJECT_ID`, `RESTIC_REPOSITORY` and `RESTIC_PASSWORD` environment variables in a shell |
| 25 | +3. List available Restic snapshots using `restic snapshots` and note the latest SHA |
| 26 | +4. Download the latest snapshot `restic dump -t pg_dumpall.sql.gz <SHA> /pg_dumpall.sql.gz` |
| 27 | +5. Uncompress the dump and make sure it is a complete dump including both schema and data |
| 28 | + |
| 29 | +### Restoring the database |
| 30 | + |
| 31 | +> ⚠️**IMPORTANT**⚠️ Every step here should be run against the `metabase-test` namespace to prevent data loss in production. |
| 32 | +
|
| 33 | +1. Visit the test instance at https://metabase-test.k8s.calitp.jarv.us/ to see that login and reporting work as expected |
| 34 | +2. Connect to the database instance `kubectl -n metabase-test exec -it database-0 -- bash` |
| 35 | +3. Ensure that `psql` can connect: `psql -U admin postgres` |
| 36 | +4. Scale the `metabase` ReplicaSet to zero: `kubectl -n metabase-test scale deployment metabase --replicas=0` |
| 37 | +5. Restore the dump to the test database: `cat pg_dumpall.sql | kubectl -n metabase-test exec -it database-0 -- psql -U admin postgres` |
| 38 | +6. Scale the `metabase ReplicaSet` to 1: `kubectl -n metabase-test scale deployment metabase --replicas=1` |
| 39 | +7. Ensure that the test instance still works |
| 40 | + |
| 41 | +### Upgrading Metabase |
| 42 | + |
| 43 | +1. Manually edit the ReplicaSet configuration for the `metabase` ReplicaSet to set the version number |
| 44 | +2. Save the configuration |
| 45 | +3. Watch the logs for the `metabase` pod until the migrations run: `kubectl -n metabase-test logs deployment/metabase --follow` |
| 46 | +4. Visit the test instance to see that login and reporting work as expected |
| 47 | + |
| 48 | +## Release |
| 49 | + |
| 50 | +1. Update the test version in `kubernetes/apps/values/metabase-test.yaml` to the version specified when editing above |
| 51 | +2. Update the production version in `kubernetes/apps/values/metabase.yaml` to the same |
| 52 | +3. Create a pull request |
| 53 | +4. Wait for the `preview-kubernetes` Github Action to run and display a diff for the Docker image tags |
| 54 | +5. Ensure those tags match the intended updates to `metabase` and `metabase-test` |
0 commit comments