First, start the rancher admin console
sudo docker run -d --restart=unless-stopped -p 443:443 rancher/rancher
Navigate to this server’s IP address in a browser
This starts an https web server with a self-signed certificate, so a security exception will need to be made.
It will prompt you to create an admin password and the server’s address. If the default address doesn’t match how the other nodes will access this server, change it here.
After this initial setup is complete, you will be taken to the dashboard. Click on “Add Cluster” and select “Custom” to setup an on-prem Kubernetes cluster.
Fill out “Cluster Name” and click next, accepting the defaults for the Kubernetes version, network provider. Cloud provider can be left at “none”. Select “Next” to create the cluster.
On the next page, you will see a command to add nodes to the new cluster. You will need at least one “Control Plane”, “etcd”, and “worker” node. Select all three, and run the generated command on one of your servers. For high-availability, make at least two servers “Control Plane” nodes, and three servers “etcd” nodes. All servers in the cluster can be worker nodes.
As you run the generated commands on the nodes, Rancher will display how many nodes have joined the cluster.
Select “Done”. The cluster will display the status as the cluster is provisioned. This can take some time. During provisioning, nodes may be highlighted in red and display what looks like an error message. This is expected during provisioning. This could take up to half an hour in some cases.
Enabling kubectl on your local machine
When the cluster completes provisioning, click on the “Kubectl Config” button toward the top of the cluster overview. Scroll to the bottom of the new window and select “Copy to Clipboard”.
On your local machine go to your home directory and create a file under .kube/config and save the copied text into this file.
Run kubectl get nodes and check that the nodes you added in Rancher appear here.
Setup storage using Longhorn
Before your deployments can write to disk, we need to setup a high-availability storage system – Longhorn in this case.
Then install/upgrade the pre-requisites on your nodes:
sudo apt update sudo apt install -y curl util-linux grep gawk open-iscsi
Click on the drop-down in the top-left that displays your cluster name. Hover over your cluster name and click on “Default” in the sub-menu. Navigate to the “Apps” tab, and click on the “Launch” button.
To install Longhorn to your cluster, search for “Longhorn” and click on “View Details” in the entry that comes up. Scroll to the bottom of the page and select “Launch”, accepting defaults.
Once the deployment is ready, click on “/index.html” in the app’s overview. This will take you to the Longhorn dashboard.
Each node will have disk space under /var/lib/rancher/longhorn. Additional disks can be added in the Longhorn dashboard, but formatting, partitioning, and mounting need to be taken care of manually on each server.