Backup & restore on Kubernetes environments
Follow the instructions below to backup and restore your Axiomatics Services Manager (ASM) Kubernetes (K8s) deployment.
Backup
Local Kubernetes (K8s) environments deployed with Minikube are intended to be used for testing purposes and their data should be non-critical and easy to regenerate. However, in order to backup the Postgres DB running on the K8s pod, follow the steps below.
Cloud environments are using RDS Postgres which offers the option to take backups automatically. Additionally, it is possible to take DB snapshots at any time that you can export, copy, and share. Finally, you can restore a DB from a snapshot. For more information, refer to the AWS documentationOpens in a new tab.
-
Enter the Pod.
kubectl exec -it deployment/db -n axiomatics-asm -- bin/bash -
Dump the databases.
pg_dump asm > /var/run/postgresql/asm.sqlpg_dump keycloak > /var/run/postgresql/keycloak.sqlpg_dump domain_manager > /var/run/postgresql/domain_manager.sqlpg_dump pd > /var/run/postgresql/pd.sql -
Exit.
exitexit -
Copy the SQL files to the host.
warningReplace the
<db_pod_name>placeholders with the name of the database pod.kubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/asm.sql ./asm.sqlkubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/keycloak.sql ./keycloak.sqlkubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/domain_manager.sql ./domain_manager.sqlkubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/pd.sql ./pd.sql
Restore
In cloud environments you can restore a DB from a snapshot. See the AWS documentationOpens in a new tab for further details.
-
Stop all Pods that use the database, including the DB Pod.
kubectl scale --replicas 0 deployment.apps/adm -n axiomatics-asmkubectl scale --replicas 0 deployment.apps/asm -n axiomatics-asmkubectl scale --replicas 0 deployment.apps/keycloak -n axiomatics-asmkubectl scale --replicas 0 deployment.apps/pd-api -n axiomatics-asmkubectl scale --replicas 0 deployment.apps/db -n axiomatics-asm -
Make sure that no PersistentVolumes (PV) or PersistentVolumeClaims (PVC) related to the Postgres database exist.
-
Check if the
dbPVC exists.kubectl get pvc --all-namespacesIf it does, delete it.
kubectl delete pvc db -n axiomatics-asm -
Check if the
dbPV exists.kubectl get pv --all-namespacesIf it does, delete it.
warningIn the following command, replace
<pvc_id>with the ID of thedbPVC.kubectl delete pv <pvc_id>
-
-
Upgrade the Helm charts.
helm upgrade -n axiomatics-asm asm -f asmcharts/values.yaml asmcharts -
Make sure that the following Pods are not running:
adm,asm,keycloak, andpd-apikubectl get pods -n axiomatics-asmIf any of these Pods are still active, stop them using the following command.
warningReplace
<pod_name>with the actual name of the running pod. For example,adm.kubectl scale --replicas 0 deployment.apps/<pod_name> -n axiomatics-asm -
If the
dbPod hasn't started automatically:-
SSH to minikube, update the permissions, and exit.
warningRun each of the following commands individually.
minikube sshsudo -icd /tmp/hostpath-provisioner/axiomatics-asmchown -R 999:999 db/exitexit -
Start the
dbPod manually.kubectl scale --replicas 1 deployment.apps/db -n axiomatics-asm
-
-
From the directory containing the backed up SQL files, copy them to the database pod.
warningReplace the
<db_pod_name>placeholders with the name of the database pod.kubectl cp ./asm.sql axiomatics-asm/<db_pod_name>:run/postgresql/asm.sqlkubectl cp ./keycloak.sql axiomatics-asm/<db_pod_name>:run/postgresql/keycloak.sqlkubectl cp ./domain_manager.sql axiomatics-asm/<db_pod_name>:run/postgresql/domain_manager.sqlkubectl cp ./pd.sql axiomatics-asm/<db_pod_name>:run/postgresql/pd.sql -
Enter the Pod.
kubectl exec -it deployment/db -n axiomatics-asm -- bin/bash -
Drop the databases. Then, create them again and run the SQL files.
psql template1 -c 'drop database asm'psql template1 -c 'drop database keycloak'psql template1 -c 'drop database domain_manager'psql template1 -c 'drop database pd'psql template1 -c 'create database asm'psql template1 -c 'create database keycloak'psql template1 -c 'create database domain_manager'psql template1 -c 'create database pd'psql asm < /run/postgresql/asm.sqlpsql keycloak < /run/postgresql/keycloak.sqlpsql domain_manager < /run/postgresql/domain_manager.sqlpsql pd < /run/postgresql/pd.sql -
Exit.
exitexit -
Start the Pods again.
kubectl scale --replicas 1 deployment.apps/adm -n axiomatics-asmkubectl scale --replicas 1 deployment.apps/asm -n axiomatics-asmkubectl scale --replicas 1 deployment.apps/keycloak -n axiomatics-asmkubectl scale --replicas 1 deployment.apps/pd-api -n axiomatics-asm