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.

Prerequisites

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.

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 version 2.x.x of the rancher-backup chart.

  1. helm repo add rancher-charts https://charts.rancher.io
  2. helm repo update
  3. helm install rancher-backup-crd rancher-charts/rancher-backup-crd -n cattle-resources-system --create-namespace --version $CHART_VERSION
  4. helm install rancher-backup rancher-charts/rancher-backup -n cattle-resources-system --version $CHART_VERSION

2. Restore from backup using a Restore custom resource

If you are using an S3 store as the backup source, and need to use your S3 credentials for restore, create a secret in this cluster using your S3 credentials. The Secret data must have two keys, accessKey and secretKey containing the s3 credentials like this:

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: s3-creds
  5. type: Opaque
  6. stringData:
  7. accessKey: <Enter your base64-encoded access key>
  8. secretKey: <Enter your base64-encoded secret key>

This secret can be created in any namespace, with the above example it will get created in the default namespace

In the Restore custom resource, prune must be set to false.

Create a Restore custom resource like the example below:

  1. # migrationResource.yaml
  2. apiVersion: resources.cattle.io/v1
  3. kind: Restore
  4. metadata:
  5. name: restore-migration
  6. spec:
  7. backupFilename: backup-b0450532-cee1-4aa1-a881-f5f48a007b1c-2020-09-15T07-27-09Z.tar.gz
  8. prune: false
  9. encryptionConfigSecretName: encryptionconfig
  10. storageLocation:
  11. s3:
  12. credentialSecretName: s3-creds
  13. credentialSecretNamespace: default
  14. bucketName: backup-test
  15. folder: ecm1
  16. region: us-west-2
  17. endpoint: s3.us-west-2.amazonaws.com

Important: The field encryptionConfigSecretName must be set only if your backup was created with encryption enabled. Provide the name of the Secret containing the encryption config file. If you only have the encryption config file, but don’t have a secret created with it in this cluster, use the following steps to create the secret:
1. The encryption configuration file must be named encryption-provider-config.yaml, and the --from-file flag must be used to create this secret. So save your EncryptionConfiguration in a file called encryption-provider-config.yaml and run this command:

  1. kubectl create secret generic encryptionconfig \
  2. --from-file=./encryption-provider-config.yaml \
  3. -n cattle-resources-system

Then apply the resource:

  1. kubectl apply -f migrationResource.yaml

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.

  1. helm install rancher rancher-latest/rancher \
  2. --namespace cattle-system \
  3. --set hostname=<same hostname as the server URL from the first Rancher server> \