K8s-to-VM database migration ¶
In September 2021, CATS’ primary database was migrated from being hosted within the application’s Kubernetes cluster to being hosted in on a dedicated VM.
Sync dedicated DB from k8s ¶
-
Connect to kubernetes cluster:
export KUBECONFIG=~/.kube/indevets-live.yaml kubectl get nodes
-
Capture name of current application pod:
APP_POD=$(kubectl -n indevets-production2 get pod -l app.kubernetes.io/name=indevets-core -o jsonpath='{.items[0].metadata.name}')
-
Scale destination system down to
0
replicas to ensure in-use resources don’t prevent a clean drop/recreate -
Put source system into maintenence mode
-
Pipe Postgres dump from k8s instance to dedicated instance:
kubectl -n indevets-production2 exec $APP_POD -c indevets-core-prod-db \ -- bash -c 'pg_dumpall --clean -U${POSTGRES_USER}' \ | ssh admin@primary.db.indevets.com sudo -u postgres psql
Tip
The password for the
admin
user onadmin@primary.db.indevets.com
is stored in BitWarden under the itemadmin@admin@primary.db.indevets.com