Skip to main content

Join Node to Cluster

Now that we have an initial node, kube config, and node-token we can join another node to the cluster.

Config File

The config file should be identical.

Join Script

Slight Change in the script. We are adding the node token and serverURL for the node to join.

#!/usr/bin/env bash
K3S_VERSION=v1.30.6+k3s1 # Must Match
K3S_URL="" # REQUIRED
TOKEN="" # REQUIRED

## Move config file into correct spot
sudo mkdir -p /etc/rancher/k3s
sudo cp ./k3s_config.yml /etc/rancher/k3s/config.yaml

## Increase Limits for FS (for grafana alloy and log collecting)
sudo sysctl fs.inotify.max_user_instances=1280
sudo sysctl fs.inotify.max_user_watches=655360


## Download and install cluster at Version
curl -sfL https://get.k3s.io \
| K3S_TOKEN=${TOKEN} INSTALL_K3S_VERSION=${K3S_VERSION} sh -s - server \
--server $K3S_URL


## For Convenience
mkdir -p $HOME/k3s
sudo cp /var/lib/rancher/k3s/server/node-token $HOME/k3s/node-token
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/k3s/k3s.yml
sudo chmod 644 $HOME/k3s/node-token

## Done
echo "${HOSTNAME} is ready!"
sudo kubectl get nodes

Deploy

However you see fit, copy these two files into the server.

The location they exist at doesnt matter.

I will put them at ~/ or $HOME

$HOME/
├── join.sh
└── k3s_config.yml

Run Script

Give Script Executable Permission

chmod +x ./join.sh

Run script

./join.sh

When it is done it will spit out your node-token (for joining other nodes) and kubeconfig in ~/k3s

$HOME/
├── k3s
│ ├── k3s.yml
│ └── node-token
├── join.sh
└── k3s_config.yml

If you havent already, add the kube config toi your local machine to access cluster api.

Repeat on additional nodes...