k3s

komovo · website-7c8b549745-qfbjf

installation

bash# single-node cluster (no traefik — use NodePort instead)
curl -sfL https://get.k3s.io | sh -s - --disable traefik

# with custom CIDR
curl -sfL https://get.k3s.io | sh -s - \
  --cluster-cidr 10.42.0.0/16 \
  --service-cidr 10.43.0.0/16 \
  --disable traefik

# check status
sudo systemctl status k3s --no-hostname
kubectl get nodes
kubectl get pods -A

configuration

bash# kubeconfig is at /etc/rancher/k3s/k3s.yaml

# for non-root access:
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

# server config file
sudo vim /etc/rancher/k3s/config.yaml
# example:
# write-kubeconfig-mode: 644
# disable: traefik
# cluster-cidr: 10.42.0.0/16
# service-cidr: 10.43.0.0/16

backup & restore

bash# backup the data directory
sudo tar czf k3s-backup-$(date +%F).tar.gz /var/lib/rancher/k3s/

# etcd snapshot (if using embedded etcd)
sudo k3s etcd-snapshot save --snapshot-dir=/opt/backups

# list snapshots
sudo k3s etcd-snapshot list --snapshot-dir=/opt/backups

# restore
sudo systemctl stop k3s
sudo k3s server --cluster-reset \
  --cluster-reset-restore-path=/opt/backups/snapshot.db
sudo systemctl start k3s

upgrade

bash# re-run install script to upgrade
curl -sfL https://get.k3s.io | sh -s -

# check current version
k3s --version