边缘计算实战:K3s与KubeEdge对比选型与落地实践
大家好,我是迪哥。边缘计算是云原生时代的新兴领域,从 K3s 到 KubeEdge,从边缘节点到边缘集群,我们经历了多种方案的演进。今天就聊聊边缘计算的选型和落地经验。
边缘计算方案对比
| 方案 | 适用场景 | 特点 |
|---|---|---|
| K3s | 轻量 K8s | 资源占用低 |
| KubeEdge | 边缘专用 | 云边协同 |
| MicroK8s | 轻量 K8s | 单机部署 |
| Rancher | 边缘管理 | 多集群管理 |
K3s 实战
安装配置
bash
# 安装服务端
curl -sfL https://get.k3s.io | sh -
# 安装客户端
curl -sfL https://get.k3s.io | K3S_URL=https://server-ip:6443 K3S_TOKEN=token sh -
部署应用
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: edge-app
spec:
replicas: 1
selector:
matchLabels:
app: edge-app
template:
metadata:
labels:
app: edge-app
spec:
nodeSelector:
node-role.kubernetes.io/edge: "true"
containers:
- name: app
image: registry.example.com/edge-app:latest
resources:
limits:
cpu: "500m"
memory: "512Mi"
KubeEdge 实战
架构
┌─────────────────────────────────────────────────────────────┐
│ KubeEdge 架构 │
├─────────────────────────────────────────────────────────────┤
│ 云端 边缘端 │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ CloudCore │◄─────────────────────►│ EdgeCore │ │
│ │ 云端控制 │ 云边通信 │ 边缘运行 │ │
│ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
安装配置
bash
# 安装云端组件
kubectl apply -f https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/cloud/crds.yaml
# 部署 CloudCore
helm install cloudcore kubeedge/cloudcore -n kubeedge
# 安装边缘节点
keadm join --cloudcore-ipport=cloudcore:10000 --token=token
部署应用
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: edge-app
spec:
replicas: 1
selector:
matchLabels:
app: edge-app
template:
metadata:
labels:
app: edge-app
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/edge
operator: Exists
spec:
containers:
- name: app
image: registry.example.com/edge-app:latest
对比选型
| 维度 | K3s | KubeEdge |
|---|---|---|
| 架构 | 轻量 K8s | 云边协同 |
| 资源占用 | 低 | 更低 |
| 云边通信 | 标准 K8s | 专用协议 |
| 适用场景 | 边缘集群 | 大规模边缘节点 |
最佳实践清单
| 维度 | 最佳实践 |
|---|---|
| 选型 | 小规模用 K3s,大规模用 KubeEdge |
| 部署 | 使用轻量镜像 |
| 网络 | 优化边缘网络连接 |
| 安全 | 启用 TLS |
| 监控 | 监控边缘节点状态 |
说到边缘计算,我家那只叫 Docker 的哈士奇最近学会了"边缘部署"------把玩具藏到家里边缘位置(沙发底下、床底下),说是这样更隐蔽,这边缘部署能力比我们的 KubeEdge 还强 😂
我是迪哥,我们下期再见!