Migrating Rancher to a New Cluster
If you are migrating Rancher to a new Kubernetes cluster, you don't need to install Rancher on the new cluster first. If Rancher is restored to a new cluster with Rancher already installed, it can cause problems.
These instructions assume you have created a backup and you have already installed a new Kubernetes cluster where Rancher will be deployed.
It is required to use the same hostname that was set as the server URL in the first cluster. If not done, downstream clusters will show as unavailable in the cluster management page of the UI, and you won't be able to click inside the cluster or on the cluster's Explore button.
Rancher version must be v2.5.0 and up
Rancher can be installed on any Kubernetes cluster, including hosted Kubernetes clusters such as Amazon EKS clusters. For help installing Kubernetes, refer to the documentation of the Kubernetes distribution. One of Rancher's Kubernetes distributions may also be used:
1. Install the rancher-backup Helm chart
Install the rancher-backup chart, using a version in the 2.x.x major version range:
Add the helm repository:
helm repo add rancher-charts https://charts.rancher.io
helm repo update
Select and set
CHART_VERSIONvariable with a 2.x.x rancher-backup release version:
helm search repo --versions rancher-charts/rancher-backup
Install the charts:
helm install rancher-backup-crd rancher-charts/rancher-backup-crd -n cattle-resources-system --create-namespace --version $CHART_VERSION
helm install rancher-backup rancher-charts/rancher-backup -n cattle-resources-system --version $CHART_VERSIONnote
The above assumes an environment with outbound connectivity to Docker Hub
For an air-gapped environment, use the Helm value below to pull the
backup-restore-operatorimage from your private registry when installing the rancher-backup Helm chart.
--set image.repository $REGISTRY/rancher/backup-restore-operator
2. Restore from backup using a Restore custom resource
Kubernetes v1.22, available as an experimental feature of v2.6.3, does not support restoring from backup files containing CRDs with the apiVersion
apiextensions.k8s.io/v1beta1. In v1.22, the default
resourceSet in the rancher-backup app is updated to collect only CRDs that use
apiextensions.k8s.io/v1. There are currently two ways to work around this issue:
Update the default
resourceSetto collect the CRDs with the apiVersion v1.
Update the default
resourceSetand the client to use the new APIs internally, with
apiextensions.k8s.io/v1as the replacement.note
When making or restoring backups for v1.22, the Rancher version and the local cluster's Kubernetes version should be the same. The Kubernetes version should be considered when restoring a backup since the supported apiVersion in the cluster and in the backup file could be different.
When using S3 object storage as the backup source for a restore that requires credentials, create a
Secretobject in this cluster to add the S3 credentials. The secret data must have two keys -
secretKey, that contain the S3 credentials.
The secret can be created in any namespace, this example uses the default namespace.
kubectl create secret generic s3-creds \
--from-literal=accessKey=<access key> \
Add your access key and secret key as values for
secretKeyin the command above.
During a migration,
prunemust be set to
false. See the example below:
encryptionConfigSecretNameshould be used only if your backup was created with encryption enabled.
If this applies, provide the name of the
Secretobject containing the encryption config file. If you only have the encryption config file, but don't have the secret created in this cluster, use the following steps to create the secret:
Create an encryption configuration file
The command below uses a file named
encryption-provider-config.yaml, with the
--from-fileflag. Run the below once the
EncryptionConfigurationis saved in a file called
kubectl create secret generic encryptionconfig \
Apply the manifest, and monitor the Restore status:
kubectl apply -f restore-migration.yaml
Watch the Restore status:
kubectl get restore
Watch the restoration logs:
kubectl logs -n cattle-resources-system --tail 100 -f -l app.kubernetes.io/instance=rancher-backup
Once the Restore resource has the status
Completed, you can continue the cert-manager and Rancher installation.
3. Install cert-manager
Follow the steps to install cert-manager in the documentation about installing cert-manager on Kubernetes.
4. Bring up Rancher with Helm
Use the same version of Helm to install Rancher, that was used on the first cluster.
For Kubernetes v1.25 or later, set
helm install rancher rancher-latest/rancher \
--namespace cattle-system \
--set hostname=<same hostname as the server URL from the first Rancher server> \
If the original Rancher environment is running, you can collect the current values with a kubeconfig for the original environment:
helm get values rancher -n cattle-system -o yaml > rancher-values.yaml
These values can be reused using the
rancher-values.yaml file. Be sure to switch the kubeconfig to the new Rancher environment.
helm install rancher rancher-latest/rancher -n cattle-system -f rancher-values.yaml --version x.y.z