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 nodesMulti-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-secretUninstall
# On server
/usr/local/bin/k3s-uninstall.sh
# On agent
/usr/local/bin/k3s-agent-uninstall.shKey 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=LoadBalancerDisable any component if you want to use alternatives:
curl -sfL https://get.k3s.io | sh -s -
--disable traefik
--disable servicelbUsing 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.comDeploy 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-passwordAir-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/k3sUse 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 是更好的长期选择。
来源与致谢
- GitHub: k3s-io/k3s — 32.7K+ ⭐ | Apache-2.0
- 官网: k3s.io