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.sql
pg_dump keycloak > /var/run/postgresql/keycloak.sql
pg_dump domain_manager > /var/run/postgresql/domain_manager.sql
pg_dump pd > /var/run/postgresql/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>:var/run/postgresql/asm.sql ./asm.sql
kubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/keycloak.sql ./keycloak.sql
kubectl cp axiomatics-asm/<db_pod_name>:var/run/postgresql/domain_manager.sql ./domain_manager.sql
kubectl 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-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
If the
db
Pod hasn't started automatically:SSH to minikube, update the permissions, and exit.
ImportantRun each of the following commands individually.
minikube ssh
sudo -i
cd /tmp/hostpath-provisioner/axiomatics-asm
chown -R 999:999 db/
exit
exitStart the
db
Pod 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.
ImportantReplace the
<db_pod_name>
placeholders with the name of the database pod.kubectl cp ./asm.sql axiomatics-asm/<db_pod_name>:run/postgresql/asm.sql
kubectl cp ./keycloak.sql axiomatics-asm/<db_pod_name>:run/postgresql/keycloak.sql
kubectl cp ./domain_manager.sql axiomatics-asm/<db_pod_name>:run/postgresql/domain_manager.sql
kubectl cp ./pd.sql axiomatics-asm/<db_pod_name>:run/postgresql/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.
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.sql
psql keycloak < /run/postgresql/keycloak.sql
psql domain_manager < /run/postgresql/domain_manager.sql
psql pd < /run/postgresql/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