DEV Community

Alex Spinov
Alex Spinov

Posted on

K3s Has a Free API: Lightweight Kubernetes for Edge Computing

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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 -
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

  1. Edge Computing: Run Kubernetes on Raspberry Pi clusters
  2. CI/CD Testing: Spin up clusters in seconds for integration tests
  3. Dev Environments: Local Kubernetes without Docker Desktop overhead
  4. 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))}")
Enter fullscreen mode Exit fullscreen mode

Resources


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)