K3s is a lightweight, certified Kubernetes distribution designed for edge computing, IoT, and resource-constrained environments. Built by Rancher Labs (now SUSE), it packages the entire Kubernetes control plane into a single binary under 100MB.
What Is K3s?
K3s is a fully CNCF-certified Kubernetes distribution that strips away cloud-provider-specific code, alpha features, and non-essential plugins to create a minimal Kubernetes. It replaces etcd with SQLite by default, making it perfect for single-node clusters and edge deployments.
Key Features:
- Single binary under 100MB
- Built-in Traefik ingress controller
- SQLite, MySQL, PostgreSQL, or etcd backend
- ARM64 and ARMv7 support
- Automatic TLS management
- Embedded containerd runtime
Quick Start
# Install K3s server
curl -sfL https://get.k3s.io | sh -
# Check cluster status
sudo k3s kubectl get nodes
# Deploy an app
sudo k3s kubectl create deployment nginx --image=nginx
sudo k3s kubectl expose deployment nginx --port=80 --type=NodePort
K3s API: Full Kubernetes API in Lightweight Package
K3s exposes the complete Kubernetes API, which means you can interact with it programmatically using any Kubernetes client library:
from kubernetes import client, config
# Load K3s kubeconfig
config.load_kube_config(config_file="/etc/rancher/k3s/k3s.yaml")
v1 = client.CoreV1Api()
# List all pods
pods = v1.list_pod_for_all_namespaces()
for pod in pods.items:
print(f"{pod.metadata.namespace}/{pod.metadata.name}: {pod.status.phase}")
# Create a namespace
namespace = client.V1Namespace(
metadata=client.V1ObjectMeta(name="my-app")
)
v1.create_namespace(body=namespace)
Multi-Node Cluster Setup
# On server node
curl -sfL https://get.k3s.io | sh -s - --cluster-init
# Get the token
sudo cat /var/lib/rancher/k3s/server/node-token
# On agent nodes
curl -sfL https://get.k3s.io | K3S_URL=https://server-ip:6443 K3S_TOKEN=<token> sh -
Helm Charts with K3s
# K3s comes with Helm controller built-in
# Create a HelmChart resource
cat <<EOF | sudo k3s kubectl apply -f -
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: prometheus
namespace: kube-system
spec:
chart: prometheus
repo: https://prometheus-community.github.io/helm-charts
targetNamespace: monitoring
EOF
K3s vs K8s: When to Use What
| Feature | K3s | K8s |
|---|---|---|
| Binary size | ~100MB | ~1GB+ |
| Memory | 512MB min | 2GB+ min |
| Setup time | 30 seconds | 30+ minutes |
| Edge/IoT | Designed for | Not ideal |
| Production | Yes (CNCF certified) | Yes |
| HA support | Yes (embedded etcd) | Yes |
Real-World Use Cases
- Edge Computing: Run Kubernetes on Raspberry Pi clusters
- CI/CD Testing: Spin up clusters in seconds for integration tests
- Dev Environments: Local Kubernetes without Docker Desktop overhead
- IoT Gateways: Orchestrate containers on ARM devices
Monitoring K3s Programmatically
from kubernetes import client, config
config.load_kube_config(config_file="/etc/rancher/k3s/k3s.yaml")
v1 = client.CoreV1Api()
# Get node metrics
nodes = v1.list_node()
for node in nodes.items:
allocatable = node.status.allocatable
print(f"Node: {node.metadata.name}")
print(f" CPU: {allocatable.get(chr(99)+chr(112)+chr(117)}")
print(f" Memory: {allocatable.get(chr(109)+chr(101)+chr(109)+chr(111)+chr(114)+chr(121))}")
Resources
- K3s Documentation
- K3s GitHub — 29K+ stars
- SUSE Rancher
Need to scrape web data for your Kubernetes-powered applications? Check out my web scraping tools on Apify — production-ready actors for Reddit, Google Maps, and more. Questions? Email me at spinov001@gmail.com
Top comments (0)