How to Install K3s on Ubuntu 22.04: A Lightweight Kubernetes Solution
K3s is a lightweight, certified Kubernetes distribution designed for edge computing, IoT, and resource-constrained environments. Developed by Rancher Labs, K3s bundles all Kubernetes components into a single binary that uses less than 512MB of RAM. In this guide, I'll walk you through installing K3s on Ubuntu 22.04 LTS (Jammy Jellyfish).
Before we begin, ensure you have:
First, let's ensure your Ubuntu system is up to date:
sudo apt update && sudo apt upgrade -y
If the upgrade includes a kernel update, consider rebooting your system:
sudo reboot
K3s requires some basic dependencies:
sudo apt install -y curl wget
There are several ways to install K3s. In this post we're going to focus on the most basic, a single node cluster that's ideal for learning and testing.
For a quick single-node installation (server and agent on the same node):
curl -sfL https://get.k3s.io | sh -
This will:
/etc/rancher/k3s/k3s.yaml
Check that K3s is running:
sudo systemctl status k3s
You should see output indicating that the service is active (running).
Verify Kubernetes cluster status:
sudo k3s kubectl get nodes
You should see your node with a status of "Ready".
By default, the kubeconfig file is stored at /etc/rancher/k3s/k3s.yaml
. To use kubectl from your regular user account:
mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $USER:$USER ~/.kube/config
export KUBECONFIG=~/.kube/config
Now you can run kubectl commands without sudo:
kubectl get nodes
For easier cluster management, you might want to install kubectl:
sudo apt install -y kubectl
You now have a working K3s cluster on Ubuntu 22.04! K3s provides all the power of Kubernetes in a lightweight package, making it ideal for development, testing, and production environments where resources are limited.
Some next steps to consider:
Happy Kuberneting with your new lightweight cluster!