What is k3s?
Prerequisite
- Servers
- Fixed Registration Address
- Option: Worker node
Create the control plane
run this script to create a control plane
curl -sfL https://get.k3s.io | sh -
Create the worker node
To join a worker node to your existing k3s control plane, you need two things from the control-plane node:
- The node token
- The control-plane node’s IP or hostname
1. Get the node token (on the control-plane node)
Run this on the machine where you installed k3s with your command:
sudo cat /var/lib/rancher/k3s/server/node-token
Copy this value.
2. Join the worker node
On the worker node, run:
curl -sfL https://get.k3s.io | K3S_URL=https://<CONTROL_PLANE_IP>:6443 K3S_TOKEN=<NODE_TOKEN> sh -
Example:
curl -sfL https://get.k3s.io | \
K3S_URL=https://192.168.1.10:6443 \
K3S_TOKEN=K10f3a9c7c0f2e7c8d9b3b1a2c3d4e5f6::server:abcdef1234567890 \
sh -
Verify the worker joined
Back on the control-plane node:
kubectl get nodes
You should see something like:
NAME STATUS ROLES AGE VERSION
master-1 Ready control-plane,master 5m v1.xx.x+k3s
worker-1 Ready <none> 1m v1.xx.x+k3s
Optional copy kubeconfig to personal pc
On the control-plane node
sudo cp /etc/rancher/k3s/k3s.yaml /tmp/k3s.yaml
sudo chown $USER:$USER /tmp/k3s.yaml
On your Ubuntu Desktop
scp user@192.0.0.1:/tmp/k3s.yaml ~/.kube/config
chmod 600 ~/.kube/config
Edit ONLY the server line
nano ~/.kube/config
change
server: https://127.0.0.1:6443
# to
server: https://<control-plane-ip>:6443
verification
kubectl config get-contexts
kubectl cluster-info
kubectl get nodes
Troubleshooting
hostname collusion
On control plane, Run :
sudo systemctl status k3s-agent
if you see 403 unable to verify password for node ubuntu-server
you might need to change worker-node's hostname
on worker node
# change hostname to worker-1
sudo systemctl stop k3s-agent || true
sudo /usr/local/bin/k3s-agent-uninstall.sh || true
sudo rm -rf /var/lib/rancher/k3s
sudo rm -rf /etc/rancher
sudo hostnamectl set-hostname worker-1
exec bash
On the CONTROL PLANE — remove the old node entry
kubectl delete node ubuntu-server || true
Also verify the token:
sudo cat /var/lib/rancher/k3s/server/node-token
Rejoin the worker with the correct token
On the worker node:
curl -sfL https://get.k3s.io | \
K3S_URL=https://<CONTROL_PLANE_IP>:6443 \
K3S_TOKEN=<NODE_TOKEN> \
sh -
sudo systemctl restart k3s-agent
=== Done ===
Leave a comment if you have any questions.
===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube
Top comments (0)