Configs2026年4月10日·1 分钟阅读

K3s — Lightweight Certified Kubernetes Distribution

K3s is a fully compliant, lightweight Kubernetes distribution that runs in less than 512MB RAM. Perfect for edge, IoT, ARM, CI/CD, and resource-constrained environments.

AI
AI Open Source · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

# Install on any Linux (takes 30 seconds)
curl -sfL https://get.k3s.io | sh -

# Check status
sudo k3s kubectl get nodes

# Run a workload
sudo k3s kubectl create deployment nginx --image=nginx
sudo k3s kubectl expose deployment nginx --port=80 --type=NodePort
介绍

K3s is a fully compliant Kubernetes distribution designed for resource-constrained environments. Built by Rancher Labs (now SUSE), it packages Kubernetes into a single binary under 100MB that uses less than 512MB of RAM, making it perfect for edge computing, IoT devices, CI/CD pipelines, and developers who want Kubernetes without the operational complexity.

With 32.7K+ GitHub stars and Apache-2.0 license, K3s is the most popular lightweight Kubernetes distribution, certified by the CNCF and used in production from home labs to large enterprises.

What K3s Does

  • Single Binary: Everything (API server, scheduler, kubelet, etc.) in one <100MB binary
  • Low Resource: Runs Kubernetes in <512MB RAM (minimum)
  • Easy Install: One curl command to install a complete cluster
  • SQLite or etcd: Lightweight SQLite backend by default, embedded etcd for HA
  • Built-in: Traefik ingress, Flannel CNI, CoreDNS, local-path storage, metrics-server
  • ARM Support: Runs on Raspberry Pi and other ARM devices
  • Air-Gap Ready: Install without internet connection
  • High Availability: HA cluster with embedded etcd (3+ server nodes)
  • Upgrade: Simple version upgrades with automatic migration

Architecture

┌─────────────────────────────────────┐
│       K3s Single Binary              │
│  ┌──────────┐  ┌──────────────┐     │
│  │API Server│  │  Scheduler   │     │
│  └──────────┘  └──────────────┘     │
│  ┌──────────┐  ┌──────────────┐     │
│  │Controller│  │   Kubelet    │     │
│  │  Manager │  │              │     │
│  └──────────┘  └──────────────┘     │
│  ┌──────────┐  ┌──────────────┐     │
│  │  Kine    │  │  Containerd  │     │
│  │ (SQLite) │  │              │     │
│  └──────────┘  └──────────────┘     │
└─────────────────────────────────────┘

K3s replaces etcd with Kine (an abstraction layer), which can use SQLite, PostgreSQL, MySQL, or embedded etcd.

Installation

Single Node (Dev/Test)

# Install server (master)
curl -sfL https://get.k3s.io | sh -

# Kubeconfig is at /etc/rancher/k3s/k3s.yaml
sudo chmod 644 /etc/rancher/k3s/k3s.yaml
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

kubectl get nodes

Multi-Node Cluster

# On the server (master) node
curl -sfL https://get.k3s.io | sh -
sudo cat /var/lib/rancher/k3s/server/node-token
# Save this token!

# On worker nodes
curl -sfL https://get.k3s.io | K3S_URL=https://server-ip:6443 K3S_TOKEN=your-token sh -

High Availability (3 servers with embedded etcd)

# First server
curl -sfL https://get.k3s.io | sh -s - server 
  --cluster-init 
  --token=shared-secret

# Additional servers
curl -sfL https://get.k3s.io | sh -s - server 
  --server https://first-server:6443 
  --token=shared-secret

Uninstall

# On server
/usr/local/bin/k3s-uninstall.sh

# On agent
/usr/local/bin/k3s-agent-uninstall.sh

Key Features

Built-in Components

K3s includes batteries-included components you'd otherwise need to install separately:

├── Traefik (v2)         — Ingress controller
├── Flannel             — CNI networking
├── CoreDNS             — DNS service
├── Metrics Server      — kubectl top support
├── Local Path Provisioner — Default storage
├── Helm Controller     — HelmChart CRD support
└── Klipper LoadBalancer — ServiceType=LoadBalancer

Disable any component if you want to use alternatives:

curl -sfL https://get.k3s.io | sh -s - 
  --disable traefik 
  --disable servicelb

Using with Rancher

# Deploy Rancher management UI on K3s
kubectl create namespace cattle-system
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.yaml

helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm install rancher rancher-stable/rancher 
  --namespace cattle-system 
  --set hostname=rancher.yourdomain.com

Deploy Helm Charts

# K3s natively supports HelmChart CRD
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
  name: grafana
  namespace: kube-system
spec:
  chart: grafana
  repo: https://grafana.github.io/helm-charts
  targetNamespace: monitoring
  valuesContent: |-
    service:
      type: LoadBalancer
    adminPassword: your-password

Air-Gap Installation

# Download K3s binary and images
wget https://github.com/k3s-io/k3s/releases/download/v1.28.0%2Bk3s1/k3s
wget https://github.com/k3s-io/k3s/releases/download/v1.28.0%2Bk3s1/k3s-airgap-images-amd64.tar.gz

# On target machine
sudo mkdir -p /var/lib/rancher/k3s/agent/images/
sudo cp k3s-airgap-images-amd64.tar.gz /var/lib/rancher/k3s/agent/images/
sudo cp k3s /usr/local/bin/
sudo chmod +x /usr/local/bin/k3s

Use Cases

Scenario Why K3s?
Edge computing Low resource, ARM support
IoT devices Raspberry Pi compatible
CI/CD pipelines Fast startup, single binary
Developer workstation Full K8s, low overhead
Home lab Easy install, full featured
Branch offices Air-gap ready
GitOps (Flux/ArgoCD) HelmChart CRD support

K3s vs Alternatives

Feature K3s K8s (kubeadm) K0s MicroK8s
Binary size ~100MB ~1GB+ ~180MB ~200MB
RAM (idle) 512MB 2GB+ 500MB 600MB
Install time 30s 30+ min 30s 60s
Backend SQLite/etcd etcd etcd dqlite
Certification CNCF certified Native CNCF certified CNCF certified
Best for Edge, dev, prod Prod at scale Prod, edge Ubuntu users

常见问题

Q: K3s 和完整 Kubernetes 功能相同吗? A: 是的。K3s 是 CNCF 认证的 Kubernetes 发行版,通过了所有一致性测试。差异只是打包方式——K3s 更小、更容易部署,但运行的是同样的 Kubernetes。

Q: 适合生产环境吗? A: 非常适合。许多公司在生产环境大规模使用 K3s。SUSE(Rancher 母公司)提供商业支持。HA 模式下(3+ 服务器节点)可以提供生产级可用性。

Q: 和 Docker Swarm 怎么选? A: 如果你需要 Docker Swarm 的简单性,选 Docker Swarm。如果你需要 Kubernetes 生态(Helm、Operators、复杂工作负载),但又不想要完整 K8s 的复杂性,选 K3s。K3s 是更好的长期选择。

来源与致谢

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产