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.
Project Homepage: K3s.io
Documentation: K3s Documentation
π 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 Nodes | Failed Node Tolerance |
---|---|
1 | 0 |
2 | 0 |
3 | 1 |
4 | 1 |
5 | 2 |
6 | 2 |
π₯οΈ 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
Official Website: K3s Official Website
Documentation: K3s Documentation
π Related
Getting Started with Kubernetes β A guide to setting up and managing Kubernetes clusters.
Using Kubernetes with Helm β Dive deeper into Helm's features for managing Kubernetes applications.
π Explore More
Explore Kubernetes Networking to learn about networking in a containerized environment.
Dive into K3s Troubleshooting for advanced troubleshooting techniques when managing your K3s clusters.
Tags π
#k3s #kubernetes #cluster #high-availability #lightweight #edge-computing