Use Velero to Back Up Private Cloud Namespaces
Introduction
Velero is a tool that you can use to back up your Kubernetes namespaces as an additional disaster recovery measure. It does not back up your database or S3 resources, so it cannot serve as your main backup method, but it can supplement the default backup process for your Mendix app.
Velero enables you to back up and restore the following Mendix objects:
storageinstances.privatecloud.mendix.com
storageplans.privatecloud.mendix.com
builds.privatecloud.mendix.com
mendixapps.privatecloud.mendix.com
Prerequisites
Before starting this how-to, make sure you have completed the following prerequisites:
- Ensure that the Mendix Operator for your private cloud cluster is in version 2.7.0 or above.
- Install the Velero client and server in version 1.9 or above. For more information, see Velero documentation.
- Create a recovery cluster.
The process of creating a recovery cluster may vary depending on the platform that you use to host your private cloud. For more information, refer to the documentation supplied by your cloud provider.
Creating a Velero Backup
To create a backup with Velero, follow these steps:
-
Stop the Mendix Operator and Mendix agent by scaling them to 0:
kubectl scale deployment mendix-agent --replicas=0 kubectl scale deployment mendix-operator --replicas=0
For Global Operator, this needs to be done for the Global Operator namespace. -
Create the backup by entering the following command:
velero create backup mendix-velero-bkp
The above command creates a backup of all your namespaces with the name mendix-velero-bkp. If you only want to back up a specific namespace, use theinclude-namespace
flag.In case of Global Operator, theinclude-namespace
flag should be used for both the Global Operator namespace and the managed namespace. -
Verify that the backup is complete by entering the following command:
velero backup describe mendix-velero-bkp
-
Restart the Mendix Operator and Mendix agent by entering the following command:
kubectl scale deployment mendix-agent --replicas=1 kubectl scale deployment mendix-operator --replicas=1
Restoring a Velero Backup
To restore a backup that you created with Velero, follow these steps:
-
Restore the backup by entering the following command:
velero restore create --from-backup mendix-velero-bkp --status-include-resources=storageinstances.privatecloud.mendix.com,storageplans.privatecloud.mendix.com,builds.privatecloud.mendix.com,mendixapps.privatecloud.mendix.com
As a best practice, it is recommended to restore all resources, as in the above example. Restoring only specific resources can result in unpredictable behavior. However, if you only want to restore a specific Kubernetes resource, use the–status-include-resources flag
, for example,–status-include-resources=storageinstances.privatecloud.mendix.com
. -
After the app has started and created the database, restore a backup of your database and S3 files.
-
Optional: After restoring the backup, add finalizers to
StorageInstances
by entering the following command:kubectl patch storageinstances $(kubectl get storageinstances --no-headers -o custom-columns=":metadata.name") -p '{"metadata":{"finalizers":["privatecloud.mendix.com/storage-provisioner"]}}' --type=merge
Adding finalizers is not required, but it is recommended as a best practice. It ensures that the Kubernetes garbage collection cleans up the storage from deleted environments.For Mendix Operator versions earlier than 2.20, usefinalizer.privatecloud.mendix.com
instead ofprivatecloud.mendix.com/storage-provisioner
in the command above.