🧱 Prerequisites (Debian)
Works great on Debian 11 / 12 (including VPS, VM, bare metal).
1️⃣ Update the system
sudo apt update &&sudo apt upgrade -y
2️⃣ Install required basics
sudo apt install -y curl ca-certificates gnupg
3️⃣ Disable swap (required for Kubernetes)
sudo sed -i '/ swap / s/^/#/' /etc/fstab
🚀 Install k3s (Single-node Control Plane)
k3s is maintained by Rancher, and the install is famously one-liner simple.
🔹 Default install (recommended) with Traefik and custom kubeconfig mode
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik" K3S_KUBECONFIG_MODE="644" sh
That’s it. Seriously.
✅ Verify Installation
Check k3s service
sudo systemctl status k3s
Check nodes
sudo k3s kubectl get nodes
You should see something like:
NAME STATUS ROLES AGEVERSION
debian Ready control-plane,master1m v1.xx.x+k3s
🧠 kubectl Setup (Optional but Recommended)
So you don’t have to type sudo k3s kubectl every time:
# Create the .kube directory in your home
mkdir -p $HOME/.kube
# Copy the k3s configuration to your local user directory
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
# Change ownership of the config to your user
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# Set the environment variable for the current session
export KUBECONFIG=$HOME/.kube/config
# Add the KUBECONFIG variable permanently to your profile
echo "export KUBECONFIG=$HOME/.kube/config" >> ~/.bashrc
Test:
kubectl get pods -A
🌐 Allow kubectl from Outside (Optional)
If you’re on a VPS and want remote access:
Edit:
sudo nano /etc/rancher/k3s/k3s.yaml
Replace:
server:https://127.0.0.1:6443
With:
server:https://<YOUR_SERVER_IP>:6443
Restart:
sudo systemctl restart k3s
➕ Add Worker Nodes (Agent)
On the server, get the token:
sudo cat /var/lib/rancher/k3s/server/node-token
On the agent 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
# All system pods
kubectl get pods -A
# Cluster info
kubectl cluster-info
# Stop / start k3s
sudo systemctl stop k3s
sudo systemctl start k3s
🧹 Uninstall (If Needed)
Server
/usr/local/bin/k3s-uninstall.sh
Agent
/usr/local/bin/k3s-agent-uninstall.sh
Top comments (0)