Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active March 17, 2022 00:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superseb/f44d51cc42c7e5a0049d393d6d2563e7 to your computer and use it in GitHub Desktop.
Save superseb/f44d51cc42c7e5a0049d393d6d2563e7 to your computer and use it in GitHub Desktop.
Move rancher/server with volumes to other host + DNS name change

Move rancher/server container with volumes to other host + change of DNS name (Host Registration URL/CATTLE_URL/API URL) for Rancher 1.6

This applies to Rancher 1.6 only

Variables used in this guide:

  1. Go to Admin -> Settings and change the Host Registration URL to http://new.test.com:8080
  2. Stop the docker container running the rancher/server image on oldhost
    1. sudo docker stop rancher_server
  3. Backup the files of the MySQL database on oldhost
    1. sudo docker run --rm --volumes-from rancher_server-v $(pwd):/backup busybox tar cvf /backup/mysql.tar /var/lib/mysql
  4. Transfer the resulting archive (mysql.tar) over from oldhost to newhost
  5. Restore the files of the MySQL database to a new data volume
    1. Create data volume: sudo docker create -v /var/lib/mysql --name rancher-data busybox true
    2. Extract archive into data volume: sudo docker run --rm --volumes-from rancher-data -v $(pwd):/backup busybox tar xvf /backup/mysql.tar
    3. Check contents of data volume: sudo docker run --rm --volumes-from rancher-data busybox ls /var/lib/mysql
  6. Run rancher/server using the data-volume on newhost
    1. docker run -d -p 8080:8080 --volumes-from=rancher-data --restart=unless-stopped rancher/server:v1.6.10
    2. Check that no SQL errors appear
  7. We need to re-register any hosts running rancher/agent because of the changed URL
    1. In the UI, go to Infrastructure -> Hosts, Add Host, Custom
    2. Copy the command and run it on every host running the rancher/agent container
  8. Because of rancher/rancher#9307 we need to delete the containers belonging to the following infrastructure services:
    1. Be aware, delete containers only, not stacks or services as they will not return otherwise.
    2. metadata
    3. healthcheck
    4. loadbalancers
    5. scheduler should recover itself, but you can delete this aswell
  9. Wait for infrastructure services to become active/green
@h3d-thanhpv
Copy link

Can this guide be applied to Rancher 2+?

@michalmikolajczyk
Copy link

Is there a guide to import a cluster, created and managed using Rancher 2.1 interface, with apps, ingresses, etc. deployed, to another Rancher instance?

I managed to do the import, but the workloads, ingresses etc., are not visible through the Rancher instance, where the cluster was imported. The apps, that were running on the imported cluster, continued to operate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment