DevOps Blog

How to Install K3s on Ubuntu 22.04: A Lightweight Kubernetes Solution

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).

Prerequisites

Before we begin, ensure you have:

  • An Ubuntu 22.04 system (physical or virtual)
  • sudo privileges
  • At least 1GB of RAM (2GB recommended)
  • At least 1 vCPU
  • Stable internet connection

Step 1: Update Your System

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

Step 2: Install Required Dependencies

K3s requires some basic dependencies:

sudo apt install -y curl wget

Step 3: Install K3s

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:

  • Download and install K3s
  • Start the K3s service
  • Set up the kubeconfig file at /etc/rancher/k3s/k3s.yaml

Step 4: Verify the Installation

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".

Step 5: Access Your Cluster

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

Step 6: (Optional) Install kubectl

For easier cluster management, you might want to install kubectl:

sudo apt install -y kubectl

Conclusion

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:

  • Deploy the Kubernetes dashboard
  • Set up persistent storage
  • Configure ingress for your applications
  • Explore the K3s add-ons ecosystem

Happy Kuberneting with your new lightweight cluster!