Skip to content

Instantly share code, notes, and snippets.

@robbuh
Created January 29, 2021 11:38
Show Gist options
  • Save robbuh/c246585e130ab343a5e44f9226d8ae49 to your computer and use it in GitHub Desktop.
Save robbuh/c246585e130ab343a5e44f9226d8ae49 to your computer and use it in GitHub Desktop.
rancher-guide

Installing Rancher on a Single Node Using Docker

A brief guide to deploying Rancher Server on a Single Node Using Docker

Create Rancher container on Docker with self-signed certificate

docker run --name rancher-server -d --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  -v /<CERT_DIRECTORY>/<FULL_CHAIN.crt>:/etc/rancher/ssl/cert.pem \
  -v /<CERT_DIRECTORY>/<PRIVATE_KEY.key>:/etc/rancher/ssl/key.pem \
  -v /<CERT_DIRECTORY>/<CA_CERTS.pem>:/etc/rancher/ssl/cacerts.pem \
  -v ${PWD}/:/var/lib/rancher \
  --privileged \
  rancher/rancher:v2.5.3

Example

docker run --name rancher-server -d --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  -v ${PWD}/certs/rancher.mydomain.com.crt:/etc/rancher/ssl/cert.pem \
  -v ${PWD}/certs/rancher.mydomain.com.key:/etc/rancher/ssl/key.pem \
  -v ${PWD}/certs/myCA.pem:/etc/rancher/ssl/cacerts.pem \
  -v ${PWD}/:/var/lib/rancher \
  --privileged \
  rancher/rancher:v2.5.3

Backup & Restore (Bound Volume)

Backup

docker ps
docker stop rancher-server
cd /opt
sudo tar -czpf rancher-2.5.0-2020-01-08.tgz rancher
docker start rancher-server

Restore

  1. Move the tarball you want to restore onto the Rancher server and place it in /opt
  2. Stop the Rancher container
  3. Move /opt/rancher to /opt/rancher.bak
  4. Extract the tarball. This will create a new /opt/rancher
  5. Start the Rancher container
docker ps
docker stop rancher-server
cd /opt
mv rancher rancher.old
tar xzpf rancher-2.5.0-2020-01-08.tgz
docker start rancher-server

Upgrade Rancher (Bound Volume)

The upgrade procedure for Rancher running in a Docker container is similar to the procedure for making and restoring a backup, except that instead of starting the existing Rancher container, we'll start a new one with the new version. Rancher will perform any upgrades on the data itself when it starts.

  1. Stop the Rancher container
  2. Create a tarball of copy from the bind-mount directory
  3. Pull the latest or desired version of the Rancher server container image
  4. Start a new container with the same certificate options as the original container, mounting the bind-mount host directory to /var/lib/rancher
  5. Verify the upgrade by logging into the new Rancher server and confirming that it is operating correctly.
  6. Delete the stopped Rancher container so that it doesn't restart if the host is rebooted.

Backup

docker ps
docker stop rancher-server
cd /opt
cp -Rp rancher rancher.bak
mv /opt/rancher.bak /asafeplace/

Upgrade

docker run --name rancher-server -d --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  -v /<CERT_DIRECTORY>/<FULL_CHAIN.crt>:/etc/rancher/ssl/cert.pem \
  -v /<CERT_DIRECTORY>/<PRIVATE_KEY.key>:/etc/rancher/ssl/key.pem \
  -v /<CERT_DIRECTORY>/<CA_CERTS.pem>:/etc/rancher/ssl/cacerts.pem \
  -v ${PWD}/:/var/lib/rancher \
  --privileged \
  rancher/rancher:v2.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment