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.
su - postgres
cd /tmp
pg_dump asm > asm.sql
pg_dump keycloak > keycloak.sql
pg_dump domain_manager > domain_manager.sql
pg_dump pd > pd.sqlExit.
exit
exitCopy the SQL files to the host.
ImportantReplace the
<db_pod_name>
placeholders with the name of the database pod.kubectl cp axiomatics-asm/<db_pod_name>:tmp/asm.sql ./asm.sql
kubectl cp axiomatics-asm/<db_pod_name>:tmp/keycloak.sql ./keycloak.sql
kubectl cp axiomatics-asm/<db_pod_name>:tmp/domain_manager.sql ./domain_manager.sql
kubectl cp axiomatics-asm/<db_pod_name>:tmp/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-asm
kubectl scale --replicas 0 deployment.apps/asm -n axiomatics-asm
kubectl scale --replicas 0 deployment.apps/keycloak -n axiomatics-asm
kubectl scale --replicas 0 deployment.apps/pd-api -n axiomatics-asm
kubectl scale --replicas 0 deployment.apps/db -n axiomatics-asmMake sure that no PersistentVolumes (PV) or PersistentVolumeClaims (PVC) related to the Postgres database exist.
Check if the
db
PVC exists.kubectl get pvc --all-namespaces
If it does, delete it.
kubectl delete pvc db -n axiomatics-asm
Check if the
db
PV exists.kubectl get pv --all-namespaces
If it does, delete it.
ImportantIn the following command, replace
<pvc_id>
with the ID of thedb
PVC.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-api
kubectl get pods -n axiomatics-asm
If any of these Pods are still active, stop them using the following command.
ImportantReplace
<pod_name>
with the actual name of the running pod. For example,adm
.kubectl scale --replicas 0 deployment.apps/<pod_name> -n axiomatics-asm
Start the
db
Pod manually if it hasn't already done so.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.
ImportantReplace the
<db_pod_name>
placeholders with the name of the database pod.kubectl cp ./asm.sql axiomatics-asm/<db_pod_name>:tmp/asm.sql
kubectl cp ./keycloak.sql axiomatics-asm/<db_pod_name>:tmp/keycloak.sql
kubectl cp ./domain_manager.sql axiomatics-asm/<db_pod_name>:tmp/domain_manager.sql
kubectl cp ./pd.sql axiomatics-asm/<db_pod_name>:tmp/pd.sqlEnter the Pod.
kubectl exec -it deployment/db -n axiomatics-asm -- bin/bash
Drop the databases. Then, create them again and run the SQL files.
su - postgres
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 < /tmp/asm.sql
psql keycloak < /tmp/keycloak.sql
psql domain_manager < /tmp/domain_manager.sql
psql pd < /tmp/pd.sqlExit.
exit
exitStart the Pods again.
kubectl scale --replicas 1 deployment.apps/adm -n axiomatics-asm
kubectl scale --replicas 1 deployment.apps/asm -n axiomatics-asm
kubectl scale --replicas 1 deployment.apps/keycloak -n axiomatics-asm
kubectl scale --replicas 1 deployment.apps/pd-api -n axiomatics-asm