Scheduled Management Backups#
Backups should be run on a schedule consistent with the policy requirements of the environment. For example a production environment might be set for "daily" backups, while a testing environment is set for "weekly".
Preparation#
Note
The following instructions are tailored for AWS. Please adapt them to your chosen platform and storage.
Before you create a manual one-off or scheduled backup, review the steps below and update your configuration accordingly:
-
Verify whether the
velero
plugins have been installed as suggested in Velero installation. If thevelero
plugins with the desired storage option are already configured, please skip the next step. -
If no
velero
plugins have yet been installed in your k0rdent cluster, start by getting the kcm management yaml file:then edit thekubectl get management kcm -n kcm-system -o yaml > management.yaml
management.yaml
file so that the velero plugin details are filled in underspec.core.kcm
:apiVersion: k0rdent.mirantis.com/v1alpha1 kind: Management metadata: name: kcm spec: # ... core: kcm: config: velero: initContainers: - name: velero-plugin-for-<PROVIDER-NAME> image: velero/velero-plugin-for-<PROVIDER-NAME>:<PROVIDER-PLUGIN-TAG> imagePullPolicy: IfNotPresent volumeMounts: - mountPath: /target name: plugins # ...
Please review Velero's Docker Hub image plugin repositories to help identify the required
<PROVIDER-NAME>
. Once the required image has been identified, select from the available tags to determine the correct<PROVIDER-PLUGIN-TAG>
. In the case of AWS, the provider-name would bevelero-plugin-for-aws
, we can select from the available tags. -
Prepare a storage location, such as an Amazon S3 bucket, to store k0rdent backups.
-
Prepare a yaml file containing a
BackupStorageLocation
object referencing aSecret
with credentials to access the cloud storage (if the multiple credentials feature is supported by the plugin). For example, you can create theBackupStorageLocation
and the relatedSecret
yaml for the Amazon S3 configuration by following these steps.First create a file called
credentials.txt
with your credentials, as in:[default] aws_access_key_id = EXAMPLE_ACCESS_KEY_ID aws_secret_access_key = EXAMPLE_SECRET_ACCESS_KEY
The IAM user being used in this configuration will require certain permissions for the appropriate Velero S3 bucket access. Review the necessary permissions here (reference the JSON policy file named
velero-policy.json
-- take care to replace${BUCKET}
with the correct bucket name).Generate the necessary base64-encoded credentials using:
base64 -w0 credentials.txt; echo
Use this base64 value in the
data.cloud
field in thecreds-and-backup-storage-location.yaml
you'll create next. Also make sure to substitute the appropriateREGION-NAME
andBUCKET-NAME
:--- apiVersion: v1 data: # base64-encoded credentials for Amazon S3 in the following format: # [default] # aws_access_key_id = EXAMPLE_ACCESS_KEY_ID # aws_secret_access_key = EXAMPLE_SECRET_ACCESS_KEY cloud: <BASE64_VALUE> kind: Secret metadata: name: cloud-credentials namespace: kcm-system type: Opaque --- apiVersion: velero.io/v1 kind: BackupStorageLocation metadata: name: aws-s3 namespace: kcm-system spec: config: region: <REGION-NAME> default: true # optional, if not set, then storage location name must always be set in ManagementBackup objectStorage: bucket: <BUCKET-NAME> provider: aws backupSyncPeriod: 1m credential: name: cloud-credentials key: cloud EOF
-
Create the necessary Kubernetes resources in your k0rdent cluster by applying the YAML to the management cluster:
kubectl apply -f creds-and-backup-storage-location.yaml kubectl apply -f management.yaml
-
Confirm that the previous steps were applied correctly:
The management configuration yaml should have the new velero plugin details, as shown in step 2.kubectl get management kcm -n kcm-system -o yaml
Now make sure the
backupstoragelocation
shows asAvailable
:kubectl get backupstoragelocation -n kcm-system
You can get more information on how to build these objects at the official Velero documentation.NAME PHASE LAST VALIDATED AGE DEFAULT aws-s3 Available 27s 2d true
Create a Management Backup#
Periodic backups are handled by a ManagementBackup
object, which uses a Cron expression
for its .spec.schedule
field.
If the .spec.schedule
field is not set, a backup on demand will be created instead.
Optionally, set the name of the .spec.backup.storageLocation
of the BackupStorageLocation
object.
The default location is the BackupStorageLocation
object with .spec.default
set to true
.
For example, you can create a ManagementBackup
object that backs up to the storage object
created in the preparation step every 6 hours
(ref: Kubernetes CronJob schedule syntax, "Vixie cron" step values). Create a YAML file called scheduled-backup.yaml
:
apiVersion: k0rdent.mirantis.com/v1alpha1
kind: ManagementBackup
metadata:
name: kcm
spec:
schedule: "0 */6 * * *"
storageLocation: aws-s3
EOF
kubectl apply -f scheduled-backup.yaml
kubectl get managementbackup
managementbackup
should show as Completed
:
NAME LASTBACKUPSTATUS NEXTBACKUP AGE
example-backup Completed 8m