This guide provides simple steps to set up a single-node K3s cluster on Ubuntu 22.04 LTS.
- Ubuntu 22.04 LTS server
- User with
sudo
privileges - Internet connectivity
Update your system packages to the latest versions.
sudo apt update && sudo apt upgrade -y
Use the official installation script to install K3s.
curl -sfL https://get.k3s.io | sh -
This will install K3s and start the service automatically.
Check the status of the K3s service.
sudo systemctl status k3s
You should see that the service is active and running.
To ensure that your K3s cluster is up and running, perform the following tests.
List all the nodes in the cluster.
kubectl get nodes
You should see output similar to:
NAME STATUS ROLES AGE VERSION
your-node Ready control-plane,master 5m v1.XX
Deploy a simple Nginx deployment to test cluster functionality.
kubectl create deployment nginx --image=nginx
Expose the Nginx deployment via a LoadBalancer service.
kubectl expose deployment nginx --type=LoadBalancer --port=80 --target-port=80
Note: K3s includes a built-in service load balancer (klipper-lb
), which allows the LoadBalancer
service type to work on a single-node cluster.
List the services to get the external IP address.
kubectl get services
You should see output like:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 10m
nginx LoadBalancer 10.43.0.123 <node-ip> 80:31234/TCP 1m
Note: The <node-ip>
should be the IP address of your K3s server. If EXTERNAL-IP
shows <pending>
, wait a few moments and run the command again.
Use curl
to access the Nginx service using the external IP.
curl http://<node-ip>:80
Replace <node-ip>
with the external IP address of your node (e.g., 192.168.1.10
).
You should see the default Nginx welcome page HTML.
Delete the test deployment and service.
kubectl delete service nginx
kubectl delete deployment nginx
If you want to access the cluster from another machine, copy the kubeconfig file.
First, display the kubeconfig file.
sudo cat /etc/rancher/k3s/k3s.yaml
Copy the content and save it to ~/.kube/config
on your local machine.
Replace 127.0.0.1
with the IP address of your K3s server.
If you need to remove K3s, run the uninstall script.
/usr/local/bin/k3s-uninstall.sh
You have successfully set up and tested a single-node K3s cluster on Ubuntu 22.04 LTS. You can now deploy your Kubernetes workloads on this cluster.