K3S

πŸͺΆ K3S Cheat-Sheet

K3S is a lightweight Kubernetes distribution designed for IoT and edge computing environments. It’s production-ready and easy to install with a binary size under 100 MB, consuming less memory compared to traditional Kubernetes setups.


πŸ” Overview

  • Product Type: Lightweight Kubernetes Distribution

  • Focus: K3S is tailored for environments that need a small footprint and minimal resource consumption, such as IoT, edge computing, and small clusters.

    • Single-Node Setup: Ideal for development and testing

    • Multi-Node Setup: High Availability (HA) configurations with embedded or external databases

    • Ease of Installation: Simple and quick installation with automated scripts


πŸ”§ Installation

You can install K3S using several methods: with an external database, embedded database, or as a single-node setup.

πŸ“Š K3s with External DB

Set up a High Availability (HA) K3s cluster backed by an external database like MySQL, PostgreSQL, or etcd.

πŸ—ƒοΈ Install Database

  • First, install MariaDB or your preferred database.

πŸ–₯️ Install Servers

To install K3s with an external database:

curl -sfL https://get.k3s.io | sh -s - server \
--token=YOUR-SECRET \
--datastore-endpoint='mysql://user:pass@tcp(ipaddress:3306)/dbname' \
--node-taint CriticalAddonsOnly=true:NoExecute \
--tls-san your-dns-name --tls-san your-lb-ip-address

[!info]
The --node-taint flag ensures that your server node won’t run workloads, only the control plane.

πŸ”’ SSL Certificates

To avoid certificate errors, you should use the --tls-san YOUR_IP_OR_HOSTNAME_HERE option to add extra IPs or hostnames to the TLS certificate.

πŸš€ Install Agents

You can install agents on additional nodes:

curl -sfL https://get.k3s.io | sh -s - agent \
--server https://your-lb-ip-address:6443 \
--token YOUR-SECRET

πŸ’Ύ K3s with Embedded DB

Set up an HA K3s cluster using K3s's built-in distributed database (etcd).

πŸ–₯️ Install the First Server

curl -sfL https://get.k3s.io | sh -s - server \
--token=YOUR-SECRET \
--tls-san your-dns-name --tls-san your-lb-ip-address \
--cluster-init

[!tip]
The --tls-san option ensures no SSL certificate errors when accessing the server via IP or hostname.

πŸ—οΈ Install Additional Servers

To add more servers:

curl -sfL https://get.k3s.io | sh -s - server \
--token=YOUR-SECRET \
--tls-san your-dns-name --tls-san your-lb-ip-address \
--server https://IP-OF-THE-FIRST-SERVER:6443

The --cluster-init option initializes the HA cluster with an embedded etcd database. You need at least 3 nodes for fault tolerance.

πŸ—“οΈ Fault Tolerance Table

Total Number of NodesFailed Node Tolerance
10
20
31
41
52
62

πŸ–₯️ Install Agents

To install agent nodes:

curl -sfL https://get.k3s.io | sh -s - agent \
--server https://your-lb-ip-address:6443 \
--token YOUR-SECRET

βš™οΈ K3s Single Node

Set up K3s as a single-node installation.

[!warning]
This setup is ideal for testing and development but may not be suitable for production.


πŸ› οΈ Manage K3S

πŸ’» Management on Server Nodes

Use the K3S-specific kubectl to manage your cluster:

k3s kubectl

πŸ“œ Download Kube Config

You can download the kubeconfig file from:

/etc/rancher/k3s/k3s.yaml

πŸ’Ύ Database Backups

🧳 etcd Snapshots

K3S stores etcd snapshots in the following directory:

/var/lib/rancher/k3s/server/db/snapshots

[!tip]
Regular backups of the etcd database are crucial for disaster recovery.


πŸ“š Resources



🌍 Explore More


Tags πŸ“š

#k3s #kubernetes #cluster #high-availability #lightweight #edge-computing