Configuring K3s nodes
We need 3 master nodes and at least 1 worker node to run K3s in HA mode.
1st master node
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
- Replace
K3S_TOKEN
with the contents of the file/var/lib/rancher/k3s/server/node-token
from the 1st master node installation. - Set
--node-name
tomaster2
. - Set
--server
to the private static IP address of the 1st master node.
Check the node status:
kubectl get nodes
3rd master node
- Replace
K3S_TOKEN
with the contents of the file/var/lib/rancher/k3s/server/node-token
from the 1st master node installation. - Set
--node-name
tomaster3
- 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
- Replace
K3S_TOKEN
with the contents of the file/var/lib/rancher/k3s/server/node-token
from the 1st master node installation. - Set
--node-name
toworker1
. - 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.
- Replace
K3S_TOKEN
with the contents of the file/var/lib/rancher/k3s/server/node-token
from the 1st master node installation. - Update
--node-name
with your worker node name(Ex: worker2, worker3 etc.) - 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: