K3s Lightweight Kubernetes
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
curl -sfL https://get.k3s.io | sh -
sudo k3s kubectl get nodes
sudo cat /var/lib/rancher/k3s/server/node-token
K3S_URL=https://<server>:6443
K3S_TOKEN=<token>
systemctl status k3s
journalctl -u k3s -f
k3s etcd-snapshot save
k3s-uninstall.sh
Concepts
- Server control plane + datastore
- Agent K3S_URL + K3S_TOKEN
- Cluster kubectl, manifests, snapshots
Install
curl -sfL https://get.k3s.io | sh -
curl -sfL https://get.k3s.io |
K3S_URL=https://<server>:6443 K3S_TOKEN=<token>
sh -
curl -sfL https://get.k3s.io |
INSTALL_K3S_VERSION=<version> sh -
INSTALL_K3S_CHANNEL=latest
INSTALL_K3S_EXEC="server --cluster-init"
INSTALL_K3S_SKIP_START=true
K3S_NODE_NAME=<name>
K3S_KUBECONFIG_MODE=644
Server and agent
k3s serverk3s agent--cluster-init--server https://<server>:6443
--token <token>
--tls-san <host-or-ip>
--disable traefik
--node-taint <key>=<value>:<effect>
--flannel-backend none
--secrets-encryption
--write-kubeconfig-mode 644
Config file
/etc/rancher/k3s/config.yaml
/etc/rancher/k3s/config.yaml.d/*.yaml
# flag names without the dasheswrite-kubeconfig-mode: "0644"tls-san: - k3s.example.comdisable: - traefiknode-taint+: - "dedicated=infra:NoSchedule"
/etc/rancher/k3s/registries.yaml
/var/lib/rancher/k3s/server/manifests/
/var/lib/rancher/k3s/agent/images/
Cluster and nodes
/etc/rancher/k3s/k3s.yaml
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
k3s kubectl get nodes
k3s kubectl get pods -A
/var/lib/rancher/k3s/server/node-token
/var/lib/rancher/k3s/server/token
k3s crictl psk3s crictl images
k3s check-config
k3s --versionService
systemctl status k3s
systemctl status k3s-agent
sudo systemctl restart k3s
journalctl -u k3s -f
journalctl -u k3s-agent -f
/usr/local/bin/k3s-killall.sh
/usr/local/bin/k3s-uninstall.sh
/usr/local/bin/k3s-agent-uninstall.sh
Tokens and certificates
k3s token create
k3s token listk3s token rotate --new-token <token>
k3s certificate check
k3s certificate rotate
k3s certificate rotate --service
<name>,<name>
Etcd and backups
k3s etcd-snapshot save
k3s etcd-snapshot save --name <name>
k3s etcd-snapshot ls
k3s etcd-snapshot delete <name>
k3s etcd-snapshot prune --snapshot-retention
<n>
--etcd-snapshot-schedule-cron "0 */6 * * *"
k3s server --cluster-reset
--cluster-reset-restore-path=<snapshot>
/var/lib/rancher/k3s/server/db/snapshots/
Recipes
# on the serversudo cat /var/lib/rancher/k3s/server/node-token# on the workercurl -sfL https://get.k3s.io | K3S_URL=https://<server>:6443 K3S_TOKEN=<token> sh -# back on the serversudo k3s kubectl get nodes
# first servercurl -sfL https://get.k3s.io | K3S_TOKEN=<secret> sh -s - server --cluster-init# more serverscurl -sfL https://get.k3s.io | K3S_TOKEN=<secret> sh -s - server --server https://<first>:6443
sudo systemctl stop k3ssudo k3s server --cluster-reset \ --cluster-reset-restore-path=<snapshot-path>sudo systemctl start k3s



