Skip to main content

Command Palette

Search for a command to run...

Set Up a k3s Kubernetes Cluster

Set up a one-node lightweight Kubernetes Cluster using k3s on an Ubuntu Server

Updated
2 min read

Why k3s?

K3s is a fully compliant Lightweight Kubernetes distribution.
Easy to install, half the memory, all in a single binary of less than 100 MB. Great for Homelab.

Demonstration

Step 1: Install prerequisites

Update packages and Install curl:

sudo apt update && sudo apt install -y curl

Install kubectl binary with curl:

## Download the latest stable kubectl binary from the official Kubernetes release repository
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

## make the downloaded binary executable
chmod +x kubectl

## Move the binary to a directory in system's PATH environment variable to make kubectl accessible from anywhere in the terminal
mv kubectl /usr/local/bin

## view kubectl version
kubectl version --output=yaml

Step 2: Disable Swap

Kubernetes requires swap to be disabled because it needs containers to stop immediately when memory is full, instead of the system using disk memory. The command comments out any swap entries in the file /etc/fstab and effectively disabling them on reboot.

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

Step 3: Install k3s with curl

curl -sfL https://get.k3s.io | sh -

Check if the k3s service is running:

sudo systemctl status k3s

Step 4: Verify cluster status with kubectl

Point kubectl to k3s config file:

mkdir -p $HOME/.kube
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown \((id -u):\)(id -g) $HOME/.kube/config
kubectl get nodes

Check whether our cluster is ready:

kubectl get nodes