Cookbook: Kubernetes Resource Migration using Velero
In this scenario, you have two Kubernetes clusters in completely separate environments (e.g., different clouds or data centers). Each cluster's kubectl and Velero CLI run on separate control machines. Backups will be stored in a shared S3 bucket (or S3-compatible object storage) that is accessible from both environments.
Prerequisites
- Velero CLI installed on the source control machine (managing the source cluster) and on the destination control machine (managing the destination cluster).
- Velero server (deployment) installed in both the source (Huawei Cloud) and destination (AWS) clusters, each pointing to the shared backup bucket.
kubectlconfigured on each control machine with context for its respective cluster (kubectl config get-contexts).- A shared S3 bucket (or S3-compatible object storage) accessible from both control machines and both Kubernetes clusters.
- Credentials (access keys or IAM roles) for the S3 bucket configured on both control machines and within Velero's backup storage configuration.
Step 1: On the source control machine, set Kubernetes context for the source cluster (Huawei Cloud)
kubectl config use-context <huawei-cloud-context>Replace <huawei-cloud-context> with the actual kubeconfig context name for the Huawei Cloud Kubernetes cluster.
Step 2: On the source control machine, take Velero backups for namespaces
- Backup all resources in namespaces
billing-guance-intlandguance-basis(backups will be uploaded to the shared S3 bucket):
velero backup create billing-guance-intl-backup --include-namespaces billing-guance-intl
velero backup create guance-basis-backup --include-namespaces guance-basis- Backup only the
redis-basisnamespace resources from themiddlewarenamespace:
If redis-basis is a namespace, back it up directly:
velero backup create redis-basis-backup --include-namespaces redis-basisIf redis-basis is a resource inside the middleware namespace, use label selectors or resource filters to back it up selectively (Velero does not support resource-level backup easily, but typically you would backup the whole namespace or exclude resources):
velero backup create middleware-redis-basis-backup --include-namespaces middleware --include-resources deployments,services,configmaps,ingresses --selector app=redis-basisConfirm the label selector matches the redis-basis resources.
Step 3: On the source control machine, verify the backups are complete and present in S3
velero backup describe billing-guance-intl-backup
velero backup describe guance-basis-backup
velero backup describe redis-basis-backupCheck backup logs and ensure status is Completed.
Step 4: On the destination control machine, set Kubernetes context for the destination cluster (AWS Singapore)
kubectl config use-context <aws-singapore-context>Replace <aws-singapore-context> with the actual kubeconfig context for the AWS Singapore cluster.
Step 5: On the destination control machine, restore the backups to the AWS cluster
- Restore
billing-guance-intlnamespace resources:
velero restore create --from-backup billing-guance-intl-backup- Restore
guance-basisnamespace resources:
velero restore create --from-backup guance-basis-backup- Restore
redis-basisresources in themiddlewarenamespace (adjust if applicable):
velero restore create --from-backup redis-basis-backupStep 6: On the destination control machine, verify resource restoration
kubectl get all -n billing-guance-intl
kubectl get all -n guance-basis
kubectl get all -n middlewareCheck if deployments, services, configmaps, ingresses, and other resources are restored as expected.
Notes
- Modify the Velero backup and restore commands as necessary if there are custom resource definitions (CRDs) that need to be included.
- If persistent volume data migration is required, additional Velero plugins or methods may be needed, but this cookbook focuses on resource migration only.
- Ensure the shared S3 bucket retention and lifecycle policies meet your organizational requirements.
- After migration, perform the configmap or secret modifications as defined in the project documentation (e.g., updating database URLs, access endpoints, etc.).