K3s is a lightweight Kubernetes distribution. Minimal footprint, single binary, stripped of non-essential components. Perfect for edge, IoT, and local dev. Fast startup, minimal memory.

What is K3s?

K3s is a certified Kubernetes distribution by Rancher Labs. It’s a stripped-down, production-grade Kubernetes for resource-constrained environments.

Key differences from full Kubernetes:

  • Single binary, easy installation
  • Embedded etcd (no separate control plane complexity)
  • Supports kubectl natively
  • ~40-50MB binary size vs. 1GB+ for full Kubernetes
  • 512MB RAM minimum vs. 1-2GB for standard Kubernetes
  • Removed non-essential features (alpha APIs, legacy auth)

Best for:

  • Local development
  • Edge computing, IoT devices
  • CI/CD runners
  • Rapid Kubernetes testing
  • Minimal resource environments

Installation on Fedora

SELinux policy (required on Fedora):

# Install container runtime SELinux policies
sudo dnf install -y container-selinux selinux-policy-base policycoreutils-python-utils

# Install k3s SELinux tracking policy
sudo dnf install -y https://rpm.rancher.io/k3s/latest/common/fedora/44/noarch/k3s-selinux-1.6-1.fc44.noarch.rpm

Install k3s:

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--selinux" sh -
sudo systemctl status k3s

Access kubeconfig:

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
# persist
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $USER ~/.kube/config

Check cluster:

kubectl cluster-info
kubectl get nodes
kubectl get pods -A

Deploy an app:

kubectl create deployment hello-k3s --image=kicbase/echo-server:1.0
kubectl expose deployment hello-k3s --type=LoadBalancer --port=8080
kubectl get svc

Access the service:

kubectl port-forward svc/hello-k3s 8080:8080
# Then visit http://localhost:8080

Control k3s service:

sudo systemctl stop k3s
sudo systemctl start k3s
sudo systemctl restart k3s
sudo systemctl status k3s
sudo systemctl enable k3s  # auto-start on reboot

Uninstall k3s:

sudo /usr/local/bin/k3s-uninstall.sh

Persistent storage (PV & PVC)

Concepts:

  • PersistentVolume (PV): Cluster-scoped resource representing actual storage (hostPath, NFS, CSI, etc.). Key fields: spec.capacity, spec.accessModes, spec.persistentVolumeReclaimPolicy (Retain keeps data after PVC deletion; Delete removes it), and volume source (e.g., hostPath).

  • PersistentVolumeClaim (PVC): Namespace-scoped request for storage. Specifies required storage size and accessModes. A PVC binds to a matching PV; pods consume storage by referencing a PVC by name.

  • Binding: PVC → PV. When PVC is deleted, the PV’s persistentVolumeReclaimPolicy determines what happens to backing storage.

Monitor:

kubectl get pods -w
kubectl logs -f deployment/dev-app
kubectl describe pod <pod-name>

Tips

  • On Fedora, install k3s-selinux package to handle SELinux contexts automatically.
  • K3s removes alpha APIs; standard Kubernetes may be needed for them.
  • Use port-forward or LoadBalancer service to expose apps locally.
  • K3s embedded etcd is suitable for dev; use external etcd for HA.
  • Run sudo systemctl enable k3s to auto-start on reboot.