Containers and Kubernetes · Intermediate · 18 min
Run a single-node Kubernetes cluster on a server with k3s
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · k3s v1.37.2+k3s1
You will install a pinned k3s release on an Ubuntu 26.04 server, configure it from one file, reach it from your laptop through a firewalled API port, and know how to snapshot, upgrade and remove it.
On this page
kind runs Kubernetes inside Docker on your laptop, which is right for learning and throwaway clusters. When you want Kubernetes on a server that stays up, k3s is the usual small option: one binary that bundles the API server, scheduler, kubelet, containerd, a network plugin, a DNS server and a storage provisioner, managed by a single systemd service.
A single-node k3s cluster is a sensible small production setup when one server's downtime is acceptable: internal tools, a staging environment, a side project, or a small product where a few minutes of downtime during an upgrade or a reboot is fine. It is the wrong choice when you need the app to survive the loss of the machine, because everything (control plane, data, workloads) lives on one disk. At that point you either add servers, or move to a managed Kubernetes service. Be honest about which case you are in before you start.
In this tutorial you install k3s v1.37.2+k3s1 on Ubuntu 26.04, set its options in a config file before the first start, check what it ships with, run a small workload, firewall the API to your own address, use the cluster from your laptop, take an etcd snapshot, plan an upgrade, and remove k3s cleanly. Commands run on the server unless a step says "on your laptop".
A note on cost and location: a single 4 GB virtual server is often the cheapest way to run Kubernetes at all, and if your users are in Africa, choosing a provider region close to them (Lagos, Nairobi or Johannesburg, where available) usually matters more for page speed than any cluster tuning.
Step 1 · Download and read the install script
k3s is installed by a shell script from get.k3s.io. Piping it straight into sh is what most guides show, but you are about to run it with root access, so save it and read it first:
mkdir -p ~/k3s-demo && cd ~/k3s-demo
curl -sfL https://get.k3s.io -o install-k3s.sh
less install-k3s.shThings worth finding as you read:
- The
INSTALL_K3S_*variables near the top.INSTALL_K3S_VERSIONpins an exact release. Without it, the script installs whatever thestablechannel points to on the day you run it, so two servers set up a week apart can end up on different versions. - Where it downloads from (GitHub releases for the version you pick) and the part that downloads the release's checksum file and checks the binary against it.
- What it writes: the
k3sbinary andkubectl,crictlandctrlinks in/usr/local/bin, a systemd unit, and an uninstall script.
The binary comes from GitHub, not the Ubuntu archive, so apt upgrade never updates it. Upgrades are your job, covered later in this tutorial.
Check it worked
grep -c INSTALL_K3S_VERSION install-k3s.sh prints a number greater than 0, and head -1 install-k3s.sh prints a shell line starting #!/bin/sh. If head shows HTML or nothing, the download failed; delete the file and download it again.
Step 2 · Write the config file before the first start
k3s reads /etc/rancher/k3s/config.yaml every time it starts. Each key matches a k3s server command-line flag, and flags that can repeat become YAML lists. Putting your choices here, rather than in install-script arguments, means they are in one file you can read, review and back up.
Some options only take effect cleanly on the first start (the datastore type, the certificate names, which bundled components exist), so write the file before installing. Replace k3s.example.com and 203.0.113.10 with your server's DNS name and public IP:
sudo mkdir -p /etc/rancher/k3s
sudo tee /etc/rancher/k3s/config.yaml > /dev/null <<'EOF'
write-kubeconfig-mode: "0600"
tls-san:
- k3s.example.com
- 203.0.113.10
cluster-init: true
disable:
- traefik
EOFWhat each line does:
write-kubeconfig-mode: "0600"keeps/etc/rancher/k3s/k3s.yamlreadable only by root. That file holds cluster-admin credentials. Many guides set0644sokubectlworks without sudo, but that hands full control of the cluster to every account on the server. Keep it private and copy it out deliberately, as later steps do.tls-sanadds names to the API server's certificate. The certificate always covers the server's own addresses; anything you will type into a kubeconfig from outside (a DNS name, a public IP behind NAT) must be listed, or kubectl refuses the connection with a certificate error.cluster-init: trueuses embedded etcd instead of the default SQLite database. On one node this costs a little more memory, and in return you get the built-ink3s etcd-snapshotcommand, scheduled snapshots, and the option to add more servers later.disable: [traefik]skips the bundled Traefik ingress controller. Leave it out if you want Traefik. Disable it when you plan to bring your own gateway, such as a Gateway API implementation, so two controllers do not compete for ports 80 and 443.
Check it worked
sudo cat /etc/rancher/k3s/config.yaml shows the four keys with your own name and IP under tls-san. YAML is picky about indentation: the list items sit two spaces in, under their key.
Step 3 · Install the pinned release
Run the script you read, with the version pinned. Run it as your normal user, not with sudo in front: it calls sudo itself for the steps that need root, and will ask for your password.
cd ~/k3s-demo
INSTALL_K3S_VERSION='v1.37.2+k3s1' sh install-k3s.shQuote the version because of the +. The script downloads the binary, verifies it, installs the systemd unit k3s.service, and starts it. The first start takes a minute or so while k3s generates certificates, starts etcd and pulls the images for the bundled components.
Check it worked
sudo systemctl is-active k3s
sudo k3s kubectl get nodes -o wideThe first command prints active. The second shows one node with your server's hostname, STATUS of Ready, roles including control-plane and etcd, and VERSION of v1.37.2+k3s1. If the node shows NotReady, wait 30 seconds and run it again. If the service is not active, sudo journalctl -u k3s -n 50 shows why; a typing mistake in config.yaml is the most common cause.
Step 4 · See what k3s bundles
k3s is more than the Kubernetes components. Look at what is running before you add anything:
sudo k3s kubectl get pods -n kube-system
sudo k3s kubectl get storageclassYou should see, give or take exact pod names:
- CoreDNS, which gives Services their DNS names inside the cluster.
- metrics-server, which makes
kubectl topand autoscaling work. - local-path-provisioner, behind the
local-pathstorage class. It creates persistent volumes as directories on the server's own disk. That is fine for one node, and it means pod data lives on the same disk as everything else: snapshots of etcd do not include it, so back up volume data separately. - ServiceLB (shown as
svclb-...pods once you create a LoadBalancer Service). It makestype: LoadBalancerServices work without a cloud provider by listening on the node's own IP on the Service's port. - No Traefik, because you disabled it. With the default config you would also see
traefikpods and ahelm-install-traefikjob.
k3s also deploys anything you drop in /var/lib/rancher/k3s/server/manifests as YAML, which is how these components are installed.
Check it worked
sudo k3s kubectl get pods -n kube-system lists coredns, local-path-provisioner and metrics-server pods in the Running state, and nothing named traefik. get storageclass shows local-path marked (default).
Step 5 · Run a small workload
Deploy a two-replica Nginx with a LoadBalancer Service on port 8080, so you see ServiceLB in action:
sudo k3s kubectl create deployment hello --image=nginx:1.30-alpine --replicas=2
sudo k3s kubectl expose deployment hello --type=LoadBalancer --port=8080 --target-port=80
sudo k3s kubectl rollout status deployment/hello
sudo k3s kubectl get service helloEXTERNAL-IP on the Service becomes the server's own IP after a few seconds, once ServiceLB's svclb-hello pod starts. Port 8080 is now answered by Nginx on that address.
Be aware that ports published this way are handled by Kubernetes' own packet rules, which UFW does not always filter. Do not assume ufw status tells the whole story: test from another network which ports answer, and only use LoadBalancer Services for ports you mean to be public.
Check it worked
curl -s "http://$(hostname -I | awk '{print $1}'):8080" | grep -o '<title>.*</title>'The output is something like <title>Welcome to nginx!</title>. sudo k3s kubectl get pods -l app=hello shows two pods in the Running state.
Step 6 · Firewall the API to your own address
The Kubernetes API listens on TCP 6443 on every address of the server. Anyone who can reach it can probe it, so open it only to the address you work from. Replace 198.51.100.25 with your laptop's public IP:
sudo ufw allow from 198.51.100.25 to any port 6443 proto tcp comment 'k3s API from my laptop'
sudo ufw allow from 10.42.0.0/16 to any comment 'k3s pods'
sudo ufw allow from 10.43.0.0/16 to any comment 'k3s services'The second and third rules come from the k3s requirements page: pods (10.42.0.0/16) and Services (10.43.0.0/16) must be able to reach the node, or DNS and the metrics server stop working once UFW is on. If you changed the cluster or service CIDR, use your ranges. Do not open 10250 (kubelet) or 8472 (Flannel VXLAN); those only matter when you add nodes.
If your home or office IP changes often (common on mobile and prepaid broadband), you will have to update the 6443 rule each time. A VPN such as WireGuard, with 6443 open only to the VPN range, is the steadier fix.
Check it worked
sudo ufw status numbered lists the three new rules, with 6443 allowed only from your IP. From any other machine, a connection to port 6443 times out.
Step 7 · Use the cluster from your laptop
Copy the admin kubeconfig to a private file in your home directory on the server, so you can fetch it without sudo:
sudo install -m 600 -o "$USER" -g "$USER" /etc/rancher/k3s/k3s.yaml ~/k3s-demo/k3s.yamlOn your laptop, fetch it into its own file, then point it at the server instead of 127.0.0.1. Replace you@k3s.example.com and k3s.example.com with your SSH login and the name or IP you put in tls-san:
mkdir -p ~/.kube
scp you@k3s.example.com:k3s-demo/k3s.yaml ~/.kube/k3s-demo.yaml
chmod 600 ~/.kube/k3s-demo.yaml
export KUBECONFIG=~/.kube/k3s-demo.yaml
kubectl config set-cluster default --server=https://k3s.example.com:6443
kubectl config rename-context default k3s-demoUsing kubectl config set-cluster rather than editing the file by hand works the same on macOS and Linux. The file k3s writes names its cluster, user and context all default; renaming the context makes it obvious which cluster you are talking to. To merge it with your other clusters, see the kubeconfig contexts tutorial linked below.
Then delete the server-side copy, so the credentials exist in one fewer place:
rm ~/k3s-demo/k3s.yamlThe copy on your laptop does not update itself. If kubectl later reports an expired certificate, copy the file again.
Check it worked
On your laptop, kubectl get nodes shows the server as Ready, and kubectl config current-context prints k3s-demo. A certificate error that mentions the name you used means it is missing from tls-san: add it to config.yaml, run sudo systemctl restart k3s, and try again.
Step 8 · Take and keep etcd snapshots
Because you set cluster-init: true, k3s already takes a snapshot every 12 hours (at 00:00 and 12:00 server time) and keeps the latest 5. Take one by hand before any risky change:
sudo k3s etcd-snapshot save --name before-upgrade
sudo k3s etcd-snapshot lsSnapshots land in /var/lib/rancher/k3s/server/db/snapshots, on the same disk as the cluster, so copy them off the server (with restic or rsync, for example) along with /var/lib/rancher/k3s/server/token. The token encrypts secrets in the datastore; a snapshot restored without the matching token is unusable. Treat both files as secrets.
To change the schedule or retention, add etcd-snapshot-schedule-cron and etcd-snapshot-retention to config.yaml and restart k3s.
Restoring replaces the whole cluster state with the snapshot. On this single server you stop k3s, run sudo k3s server --cluster-reset --cluster-reset-restore-path=<path-to-snapshot>, wait for the message saying it is ready to restart without --cluster-reset, and start k3s again. Practise this on a spare server before you need it.
Check it worked
sudo k3s etcd-snapshot ls lists a snapshot whose name starts with before-upgrade, with a size and a creation time from the last few minutes.
Step 9 · Upgrade with the system-upgrade-controller
Two ways to upgrade work: rerun the install script with a newer INSTALL_K3S_VERSION, or let the system-upgrade-controller do it from inside the cluster. The controller is worth setting up because the target version lives in a YAML file you can keep in Git. Install a pinned release of it from your laptop:
SUC=v0.21.1
kubectl apply -f "https://github.com/rancher/system-upgrade-controller/releases/download/${SUC}/crd.yaml" \
-f "https://github.com/rancher/system-upgrade-controller/releases/download/${SUC}/system-upgrade-controller.yaml"Then write a Plan. It must live in the system-upgrade namespace, where the controller runs. The version line below is a placeholder: replace <next-k3s-release> with a full release newer than v1.37.2+k3s1 from the k3s releases page, such as v1.37.3+k3s1 once it is out of release candidate (at the time of writing it was still an -rc). Do not apply the Plan until such a release exists:
apiVersion: upgrade.cattle.io/v1
kind: Plan
metadata:
name: k3s-server
namespace: system-upgrade
spec:
concurrency: 1
cordon: true
nodeSelector:
matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: In
values: ["true"]
serviceAccountName: system-upgrade
upgrade:
image: rancher/k3s-upgrade
version: <next-k3s-release>On your laptop, create a folder for it and save the Plan there as ~/k3s-demo/k3s-server-plan.yaml:
mkdir -p ~/k3s-demoBefore applying it, take a snapshot (previous step), upgrade only one minor version at a time, and expect a short outage: on a single node there is nowhere else for pods to run while k3s restarts.
kubectl apply -f ~/k3s-demo/k3s-server-plan.yaml
kubectl -n system-upgrade get plans,jobsCheck it worked
With a real release in version, kubectl -n system-upgrade get jobs shows an apply-k3s-server-... job whose COMPLETIONS reaches 1/1 after a few minutes. Afterwards kubectl get nodes shows the node Ready with the new release in VERSION. If the job keeps failing with an image pull error, the version you set is not a published release: fix it and apply the Plan again.
Step 10 · Clean up or uninstall
Remove the demo workload when you are done with it:
kubectl delete service hello
kubectl delete deployment helloTo remove k3s itself, read the warning first: the uninstall script stops every pod and deletes the cluster datastore, all local-path volume data, the node configuration and the k3s tools. Copy off any snapshots and volume data you want to keep before running it. On the server:
sudo /usr/local/bin/k3s-uninstall.sh
sudo rm -rf ~/k3s-demo /etc/rancher/k3sThen remove the three UFW rules you added (find their numbers with sudo ufw status numbered and delete them with sudo ufw delete <number>, highest number first). On your laptop, delete ~/.kube/k3s-demo.yaml and ~/k3s-demo, then run unset KUBECONFIG (or close that terminal) so kubectl stops pointing at a file that no longer exists.
Check it worked
On the server, command -v k3s prints nothing and systemctl status k3s reports that the unit could not be found. sudo ufw status no longer mentions 6443 or the 10.42 and 10.43 ranges.
Next steps
- If you have more than one cluster, merge this kubeconfig with the others and switch between them in Switch between Kubernetes clusters and namespaces with kubeconfig contexts.
- Go back over firewall basics, including the SSH lock-out order, in Set up the UFW firewall on Ubuntu 26.04.
- For throwaway clusters on your laptop, Run your first Kubernetes cluster with kind is faster to create and delete.
Related tutorials
- How to Run Your First Kubernetes Cluster Locally with kindYou will create a one-node Kubernetes 1.37 cluster inside Docker with kind, talk to it with kubectl, run a pod from a public image and from an image built on your own machine, and delete the cluster when you are done.
- Switch between Kubernetes clusters and namespaces with kubeconfig contextsYou will build two kubeconfig files by hand, merge them, switch clusters and namespaces with kubectl and kubectx, export a single context for someone else, and keep production behind a confirmation prompt.
- How to Set Up a UFW Firewall on Ubuntu 26.04You will turn on UFW with a deny-by-default policy, allow SSH before you enable it so you stay connected, open only the web ports your server needs, and learn to list, remove and limit rules.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials