This guide will help you set up a lightweight Kubernetes cluster using k3sup. The script automates the installation of K3s on multiple nodes, setting up a primary server and joining additional nodes.
Before running the script, ensure you have the following:
- A set of Linux servers (e.g., cloud VMs or Raspberry Pis) with SSH access
- SSH key-based authentication set up for the user running the script
k3sup
installed on your local machine (Installation Guide)
The script installs K3s on the primary server with TLS settings and saves the kubeconfig locally:
echo "Setting up primary server 1"
k3sup install --host <PRIMARY_SERVER_IP> \
--user <SSH_USER> \
--sudo \
--ssh-key ~/.ssh/id_rsa \
--cluster \
--local-path kubeconfig \
--context default \
--k3s-extra-args "--tls-san <ADDITIONAL_IPS>"
The script fetches the node-token
, which is required for adding worker nodes:
export NODE_TOKEN=$(k3sup node-token --host <PRIMARY_SERVER_IP> --user <SSH_USER>)
To add more nodes to the cluster, the script runs:
echo "Setting up additional server: 2"
k3sup join \
--host <NODE_IP> \
--server-host <PRIMARY_SERVER_IP> \
--server \
--user <SSH_USER> \
--ssh-key ~/.ssh/id_rsa \
--sudo \
--k3s-extra-args "--node-label node.kubernetes.io/worker=true"
Repeat this step for each additional node you want to add.
-
Update the script with the correct server IPs and SSH user.
-
Ensure your SSH key is in place (
~/.ssh/id_rsa
by default). -
Run the script:
chmod +x k3sup.sh ./k3sup.sh
Once the script completes, you can check the cluster status:
kubectl --kubeconfig kubeconfig get nodes
You should see all your nodes listed as Ready
.
- Ensure firewall rules allow traffic on required ports (e.g., 6443 for API server).
- Verify SSH access between the nodes.
- Check K3s logs for errors:
journalctl -u k3s -f
on each node.
Now that your cluster is up and running, you can deploy applications using Kubernetes manifests or Helm charts. Happy clustering!