Configuring K3s nodes

We need 3 master nodes and at least 1 worker node to run K3s in HA mode.

Note: The nodes must be homogeneous, having the same number of CPUs, RAM and disk space.

1st master node

To get started launch a server node using the cluster-init flag:
curl -sfL https://assets.master.k3s.getvisibility.com/k3s/k3s.sh | INSTALL_K3S_VERSION="v1.26.10+k3s1" K3S_KUBECONFIG_MODE="644" sh -s - server --node-name=master1 --cluster-init

Check for your first master node status, it should have the Ready state:

kubectl get nodes

Use the following command to copy the TOKEN that will used to join the other nodes to the cluster:

cat /var/lib/rancher/k3s/server/node-token

Do not forget to copy the private IP address of the 1st master node which will be used by the other nodes to join the cluster.

2nd master node

SSH into the 2nd server to join it to the cluster:
  1. Replace K3S_TOKEN with the contents of the file /var/lib/rancher/k3s/server/node-token from the 1st master node installation.
  2. Set --node-name to master2.
  3. Set --server to the private static IP address of the 1st master node.

Check the node status:

kubectl get nodes

3rd master node

SSH into the 3rd server to join it to the cluster:
  1. Replace K3S_TOKEN with the contents of the file /var/lib/rancher/k3s/server/node-token from the 1st master node installation.
  2. Set --node-name to master3
  3. Set --server to the private static IP address of the 1st master node.
    curl -sfL https://assets.master.k3s.getvisibility.com/k3s/k3s.sh | K3S_TOKEN=SHARED_SECRET INSTALL_K3S_VERSION="v1.26.10+k3s1" K3S_KUBECONFIG_MODE="644" sh -s - server --node-name=master3 --server https://<ip or hostname of master1>:6443

Check the node status:

kubectl get nodes

1st worker node

SSH into the 4th server to join it to the cluster:
  1. Replace K3S_TOKEN with the contents of the file /var/lib/rancher/k3s/server/node-token from the 1st master node installation.
  2. Set --node-name to worker1.
  3. Set --server to the private static IP address of the 1st master node.
    curl -sfL https://assets.master.k3s.getvisibility.com/k3s/k3s.sh | K3S_TOKEN=SHARED_SECRET INSTALL_K3S_VERSION="v1.26.10+k3s1" K3S_KUBECONFIG_MODE="644" sh -s - agent --node-name=worker1 --server https://<ip or hostname of any master node>:6443

Joining additional worker nodes

You may create as many additional worker nodes as you want.

SSH into the server to join it to the cluster:
  1. Replace K3S_TOKEN with the contents of the file /var/lib/rancher/k3s/server/node-token from the 1st master node installation.
  2. Update --node-name with your worker node name(Ex: worker2, worker3 etc.)
  3. Set --server to the private static IP address of the 1st master node.
    curl -sfL https://assets.master.k3s.getvisibility.com/k3s/k3s.sh | K3S_TOKEN=SHARED_SECRET INSTALL_K3S_VERSION="v1.26.10+k3s1" K3S_KUBECONFIG_MODE="644" sh -s - agent --node-name=workerX --server https://<ip or hostname of any master node>:6443

Check the node status: kubectl get nodes.

.

Register HA K3s Cluster to Rancher

You may run the registration command that you generated using Rancher UI or through license manager. You should see all master and worker nodes in your cluster through the Machine Pools on the Rancher dashboard: