
Setting Up a K3s Kubernetes Cluster
K3s is a lightweight, certified Kubernetes distribution designed for resource-constrained environments like edge devices, IoT, and home labs. This guide will walk you through setting up a production-ready K3s cluster.
Prerequisites
- At least two machines (physical or virtual) for high availability
- Ubuntu 20.04 LTS or newer
- At least 2GB RAM per node
- 20GB+ storage per node
- Network connectivity between all nodes
Installing the Server Node
First, let’s install the primary server node:
curl -sfL https://get.k3s.io | sh -s - server \
--cluster-init \
--tls-san=server-ip-or-hostname \
--disable traefik \
--disable servicelb
This initializes the cluster with:
- HA enabled with
--cluster-init
- Custom TLS SAN for API server
- Disabled default traefik ingress (we’ll use Nginx)
- Disabled default ServiceLB (we’ll use MetalLB)
Installing Agent Nodes
On each worker node, run:
curl -sfL https://get.k3s.io | K3S_URL=https://server-ip:6443 K3S_TOKEN=node-token sh -
Replace server-ip
with your server’s IP and get the token from /var/lib/rancher/k3s/server/node-token
on the server.
Adding High Availability
For HA, add additional server nodes:
curl -sfL https://get.k3s.io | sh -s - server \
--server https://first-server-ip:6443 \
--token node-token \
--tls-san=this-server-ip \
--disable traefik \
--disable servicelb
Setting Up Persistent Storage
We’ll use Longhorn for distributed storage:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
Longhorn provides replicated block storage across your nodes for high availability.
Next Steps
After setting up your cluster, you might want to:
- Install a proper ingress controller (Nginx, Traefik)
- Set up a load balancer (MetalLB)
- Configure monitoring with Prometheus and Grafana
- Implement GitOps with Flux or ArgoCD
Stay tuned for detailed guides on each of these topics!
This guide provides a starting point for your journey with K3s Kubernetes. In future posts, we’ll dive deeper into advanced configurations.