Skip to content

Instantly share code, notes, and snippets.

@patrick0057
Last active March 17, 2021 13:13
Show Gist options
  • Save patrick0057/c38aa046c2609307f16b372dfbd614d6 to your computer and use it in GitHub Desktop.
Save patrick0057/c38aa046c2609307f16b372dfbd614d6 to your computer and use it in GitHub Desktop.
Change Rancher 2.x server-url

Change Rancher 2.x server-url

Single server installation

During this tutorial it is recommended to use the rancher-single-tool for Rancher single server installations. It isn't required but it makes the process much easier. As a result this guide will be based on using that tool.

  1. Download the rancher-single-tool to the node that is running your rancher server container.

       curl -LO https://github.com/patrick0057/rancher-single-tool/raw/master/rancher-single-tool.sh
       wget https://github.com/patrick0057/rancher-single-tool/raw/master/rancher-single-tool.sh
  2. Backup your Rancher installation.

    bash rancher-single-tool.sh -t'backup'
  3. Login to the Rancher web interface, navigate to the Global view by clicking the dropdown in the top left corner of the screen and selecting "Global". Then click "settings" in the middle of the top bar. From the settings page, change the server-url to match your new server url.

  4. Now we need to upgrade your Rancher container to reflect new certs. This is required in most cases with the exception of already using a wildcard that also encompasses the new server-url.

    a. To generate a new self signed certificate for your new URL use the following upgrade command. Follow the prompts to finish the upgrade.

    bash rancher-single-tool.sh -t'upgrade' -s'newhostname.company.com'

    b. To generate a new Let's Encrypt certificate you will need to change the Rancher server options to reflect this. You could do this with the following command.

    bash rancher-single-tool.sh -t'upgrade' -r'--acme-domain newhostname.company.com'

    c. If you were using certificates signed by a recognized CA before and just need to replace them, you should modify the docker options to reflect this change. Keep in mind that if you just replaced the cert files on the host path and the filenames didn't change, you can just restart the docker container. However if the filenames did change, I'm providing the example below of how you would do upgrade the container to see this change.

    bash rancher-single-tool.sh -t'upgrade' -d'-d -p 443:443 -p 80:80 --restart=unless-stopped --volume=/etc/rancherssl/certs/cert.pem:/etc/rancher/ssl/cert.pem --volume=/etc/rancherssl/certs/key.pem:/etc/rancher/ssl/key.pem'

    d. If you were using certificates signed by a private CA or you want to use your own self signed certifiactes (certificates not created by rancher-single-tool option -s). Below is an example of how you would do that. The same rule applies from option c. If the filenames have not changed you don't need to upgrade, you can just restart the container.

    bash rancher-single-tool.sh -t'upgrade' -d'-d -p 443:443 -p 80:80 --restart=unless-stopped --volume=/etc/rancherssl/certs/cert.pem:/etc/rancher/ssl/cert.pem --volume=/etc/rancherssl/certs/key.pem:/etc/rancher/ssl/key.pem --volume=/etc/rancherssl/certs/ca.pem:/etc/rancher/ssl/cacerts.pem'
  5. Once your Rancher container is backup and running you need to login to a single controlplane node for each of the downstream clusters and run the cluster-agent-tool. Please see https://gist.github.com/patrick0057/d5e99957a6e77cf2975774d03d9984f3

HA installation

  1. Ensure that you have current etcd backups for your local rancher cluster.

  2. Login to the Rancher web interface, navigate to the Global view by clicking the dropdown in the top left corner of the screen and selecting "Global". Then click "settings" in the middle of the top bar. From the settings page, change the server-url to match your new server url.

  3. Log into a box where you have helm and kubectl installed. You will need your local Rancher cluster kubeconfig, ensure that it is set to the default config by either placing it in ~/.kube/config or by setting your KUBECONFIG environment variable.

  4. Check current helm chart options:

    $ helm get values rancher
    hostname: rancher.company.com
    rancherImageTag: v2.2.6
  5. Craft an upgrade command based on the values provided in the previous step and then modify the hostname to match the new server hostname/url.

    helm upgrade rancher rancher-stable/rancher --set hostname=newrancher.company.com --set rancherImageTag=v2.2.6
  6. Run the upgrade command then wait for rollout to complete.

    kubectl -n cattle-system  rollout status deploy/rancher
  7. Once your Rancher deployment is back up and running you need to login to a single controlplane node for each of the downstream clusters and run the cluster-agent-tool. Please see https://gist.github.com/patrick0057/d5e99957a6e77cf2975774d03d9984f3

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