Velero (the previous version is called Heptio Ark), an open-source tool, can safely back up and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes. Deploying Velero in the TKE cluster or self-built Kubenetes cluster, it can achieve the following features:
For more information about Velero, see Velero official document. This document describes how to use Velero to seamlessly migrate and replicate cluster resources among TKE clusters.
Install Velero instances on both the cluster to migrate and the target cluster. The Velero instances of the two clusters point to the same COS location. The process is as follows:
The migration principle is shown as follows:
Service Account Secret
hostPath
secrets
and configmaps
--use-restic
and --default-volumes-to-restic
are enabled during the Velero installation. For the installation steps, see Configuring Storage and Installing Velero.Before backing up cluster A, you can view the resources and services of cluster A for Migration Result Verification after cluster restoration.
Note:
You can specify some custom Hook operations during the backup. For example, the data in the memory of the running application needs to be persisted to disk before backup. For more information about Hook, see Backup Hooks.
velero create backup -h
to view the available resource filter parameters.velero backup create <BACKUP-NAME> --exclude-namespaces <NAMESPACE>
This document takes the creation of a “default-all” cluster backup as an example. The backup process is shown in the figure below. If the status of the backup task is "Completed", the backup is successful.Note:
You can also set regular automatic backups for Velero. Run the command
velero schedule -h
to view the setting method.
velero backup logs <BACKUP-NAME> | grep error
Note:
Please make sure that no errors occur during the backup. If Velero makes any errors during the backup, please re-perform the backup after troubleshooting.
kubectl patch backupstoragelocation default --namespace velero \
--type merge \
--patch '{"spec":{"accessMode":"ReadOnly"}}'
Before performing a restoration in cluster B, you can view the resources and services of cluster B for Migration Result Verification after cluster restoration.
Before the restoration, there are no workload resources under the “default” and “default2” namespaces in cluster B. Run the following commands to view the Pods and PVC resources in the two namespaces in cluster B, as shown below:
Run the following command to temporarily update Velero backup storage location in cluster B to read-only mode (optional, to prevent Velero from creating or deleting backup objects in the backup storage location during the restoration), as shown below:
kubectl patch backupstoragelocation default --namespace velero \
--type merge \
--patch '{"spec":{"accessMode":"ReadOnly"}}'
Note:
You can specify a custom Hook operation to perform during the restoration or after the resource restoration. For example, you need to perform a custom database restoration operation before the database application container starts. For more information about Hook, see Restore Hooks.
Before the restoration, you need to ensure that the Velero resource in cluster B is synchronized with the backup file in COS. You can use --backup-sync-period
to configure the synchronization interval, which is 1 minute by default. You can run the following command to check whether the backup of cluster A has been synchronized.
velero backup get <BACKUP-NAME>
After the backup is successfully obtained and checked, run the following command to restore all contents to cluster B.
velero restore create --from-backup <BACKUP-NAME>
The restoration process is shown in the figure below:
After the restoration is completed, check the restoration log, and run the following command to check whether there are any errors and skips during restoration, as shown below:
# Check whether there are restoration errors during migration
velero restore logs <BACKUP-NAME> | grep error
# View the skipped restoration operations during migration
velero restore logs <BACKUP-NAME> | grep skip
As shown in the figure below, you can find that no errors occurred, but some "skipped" steps occurred during restoration. Because when backing up cluster resources, all cluster resources that did not contain the Velero namespace were backed up. Some cluster resources of the same type and name already existed. For example, cluster resources under kube-system. When there is a resource conflict during the restoration, Velero will skip the restoration step. In fact, the restoration process is normal and the “skipped” logs can be ignored (you can analyze these logs as needed).
kubectl patch backupstoragelocation default --namespace velero \
--type merge \
--patch '{"spec":{"accessMode":"ReadWrite"}}'
This document mainly introduces the principle, notes and operation methods of using Velero to migrate cluster resources among TKE clusters. The cluster resources in cluster A are successfully migrated seamlessly to cluster B. The whole migration process is simple and fast, and it is a very friendly cluster resource migration solution.
Was this page helpful?