🧱 Prerequisites (Debian / Ubuntu)

Works great on:

  • Debian 11 / 12
  • Ubuntu 20.04 / 22.04
  • VPS, VM, or bare metal

1️⃣ Update the system

sudo apt update && sudo apt upgrade -y

2️⃣ Install required packages

sudo apt install -y curl ca-certificates gnupg

3️⃣ Disable swap (required for Kubernetes)

sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab

🚀 Install k3s (Single-node Control Plane)

k3s is maintained by Rancher, and the install is famously a one-liner.

🔹 Install k3s (Traefik disabled, kubeconfig readable)

curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC="--disable traefik" \
K3S_KUBECONFIG_MODE="644" sh -

✔ Installs k3s ✔ Disables Traefik (useful if you plan to install your own ingress) ✔ Makes kubeconfig readable without sudo


✅ Verify Installation

Check k3s service

sudo systemctl status k3s

Check nodes

sudo k3s kubectl get nodes

Expected output:

NAME     STATUS   ROLES                  AGE   VERSION
debian   Ready    control-plane,master   1m    v1.xx.x+k3s

So you don’t have to type sudo k3s kubectl every time:

mkdir -p $HOME/.kube
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo 'export KUBECONFIG=$HOME/.kube/config' >> ~/.bashrc
source ~/.bashrc

Test:

kubectl get pods -A

🌐 Allow kubectl Access from Outside (VPS)

If you want to access the cluster remotely.

Edit kubeconfig:

sudo nano /etc/rancher/k3s/k3s.yaml

Change:

server: https://127.0.0.1:6443

To:

server: https://<YOUR_SERVER_IP>:6443

Restart k3s:

sudo systemctl restart k3s

⚠️ Make sure port 6443 is open in your firewall / security group.


➕ Add Worker Nodes (Agents)

On the control-plane node

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

On the worker node

curl -sfL https://get.k3s.io | \
K3S_URL=https://<SERVER_IP>:6443 \
K3S_TOKEN=<NODE_TOKEN> sh -

Verify:

kubectl get nodes

🔥 Common Useful Commands

kubectl get pods -A
kubectl cluster-info
sudo systemctl stop k3s
sudo systemctl start k3s

🧹 Uninstall k3s

Server

/usr/local/bin/k3s-uninstall.sh

Agent

/usr/local/bin/k3s-agent-uninstall.sh