Skip to content

Instantly share code, notes, and snippets.

@patrick0057
Last active May 12, 2019 16:31
Show Gist options
  • Save patrick0057/eb001d60cec870d00bb1b3fa39a37d1c to your computer and use it in GitHub Desktop.
Save patrick0057/eb001d60cec870d00bb1b3fa39a37d1c to your computer and use it in GitHub Desktop.
Unsupported procedure to change Rancher server hostname and propagate changes to downstream clusters

Change Rancher 2.x server hostname

Credit for the information in this document goes to Superseb. I am just publishing it in an easy to follow gist for later use. Before starting on this guide ensure you have offline backups of etcd for your local Rancher cluster and all of your downstream clusters. Steps outlined in this document are unsupported, use at your own risk. I recommend performing steps in a test environment first.

  1. Navigate to Global> Settings> then find server-url in the list, click the triple dot and then "Edit'. Change the server-url to your desired value.

  2. Navigate to https://$server-url/v3/clusterregistrationtoken?clusterId=$CLUSTERID and grab the value from Data> insecureCommand>

    • Example value:

      curl --insecure -sfL https://$server-url/v3/import/2bdrqnkjzc7rbjsvg6j6dv9hgttmjgl84dw8tz775qkczq8qkkhh6t.yaml | kubectl apply -f -`
      
  3. Execute the insecureCommand value against your local Rancher cluster, if you are on a single Rancher installation you'll want to exec into your Rancher container to do this.

    $ curl --insecure -sfL https://$server-url/v3/import/2bdrqnkjzc7rbjsvg6j6dv9hgttmjgl84dw8tz775qkczq8qkkhh6t.yaml | kubectl apply -f -
    namespace/cattle-system unchanged
    serviceaccount/cattle unchanged
    clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding unchanged
    secret/cattle-credentials-fcf641b created
    clusterrole.rbac.authorization.k8s.io/cattle-admin unchanged
    deployment.extensions/cattle-cluster-agent configured
    daemonset.extensions/cattle-node-agent configured
  4. For each non imported downstream cluster, grab the agent run command. You can do this by navigating to https://$server-url/v3/clusterregistrationtoken?clusterId=$CLUSTERID then grabbing the value of data> nodeCommand>.

    • Example:

      sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.2 --server https://$server-url --token 2bdrqnkjzc7rbjsvg6j6dv9hgttmjgl84dw8tz775qkczq8qkkhh6t --ca-checksum 615c60b18912f6711270865f478e5a3890284e4a2ff643350ab09544e4ff2a92
  5. Modify the agent command to have the exact same roles as it was originally setup with and ensure $server-url matches the new url and is accessible then run the command on each node. If you don't match the roles up exactly as they were this will cause the node to go into a bad state. Flags for each role can be found below as well as an example of the above command with the roles.

    • roles flags: --etcd --controlplane --worker

    • Example command with controlplane and etcd roles:

      sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.2 --server https://$server-url --token 2bdrqnkjzc7rbjsvg6j6dv9hgttmjgl84dw8tz775qkczq8qkkhh6t --ca-checksum 615c60b18912f6711270865f478e5a3890284e4a2ff643350ab09544e4ff2a92 --etcd --controlplane
      
  6. Log into each node of your downstream clusters, delete your old cattle agents using docker rm -f $image_id. If all went well your new cattle agents should have reconnected to Rancher.

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