Files
k3s-configs/QUICK-REFERENCE.md
K3s Admin a725f0f933 Add k3s cluster expansion documentation and scripts
- Complete expansion guide for 2/4/6 node scenarios
- Quick join scripts for worker and master nodes
- Health check and diagnostic scripts
- Quick reference card for common operations
2026-01-21 09:02:47 +00:00

162 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# K3s 集群扩展快速参考
## 🚀 快速开始
### 当前集群信息
```
Master IP: 134.195.210.237
Token: K109d35a131f48b4d40b162398a828b766d60735f29dd7b4a37b030c1d1c0e26b23::server:72e04c3a9e3e762cbdefffc96f348a2d
```
### 一键加入脚本
#### Worker 节点(最简单)
```bash
# 在新节点上执行
sudo bash scripts/join-worker.sh
```
#### Master 节点HA 模式)
```bash
# 在新节点上执行
sudo bash scripts/join-master.sh
```
---
## 📊 扩展方案对比
| 方案 | 节点配置 | 适用场景 | 高可用 | 成本 |
|------|---------|---------|--------|------|
| **2节点** | 1M + 2W | 开发/测试 | ❌ | 💰 |
| **4节点** | 3M + 4W | 生产环境 | ✅ | 💰💰💰 |
| **6节点** | 3M + 6W | 大规模生产 | ✅ | 💰💰💰💰 |
M = Master, W = Worker
---
## 🔧 手动加入命令
### Worker 节点
```bash
export MASTER_IP="134.195.210.237"
export NODE_TOKEN="K109d35a131f48b4d40b162398a828b766d60735f29dd7b4a37b030c1d1c0e26b23::server:72e04c3a9e3e762cbdefffc96f348a2d"
curl -sfL https://get.k3s.io | K3S_URL=https://${MASTER_IP}:6443 \
K3S_TOKEN=${NODE_TOKEN} sh -
```
### Master 节点(需要先配置负载均衡器)
```bash
export FIRST_MASTER="134.195.210.237"
export LB_IP="<负载均衡器IP>"
export NODE_TOKEN="K109d35a131f48b4d40b162398a828b766d60735f29dd7b4a37b030c1d1c0e26b23::server:72e04c3a9e3e762cbdefffc96f348a2d"
curl -sfL https://get.k3s.io | sh -s - server \
--server https://${FIRST_MASTER}:6443 \
--token ${NODE_TOKEN} \
--tls-san=${LB_IP} \
--write-kubeconfig-mode 644
```
---
## ✅ 验证命令
```bash
# 查看节点
kubectl get nodes -o wide
# 健康检查
bash scripts/check-node-health.sh
# 查看节点详情
kubectl describe node <node-name>
# 查看资源使用
kubectl top nodes
```
---
## 🏷️ 节点标签
```bash
# Worker 节点
kubectl label nodes <node> node-role.kubernetes.io/worker=worker
# 功能标签
kubectl label nodes <node> workload=web
kubectl label nodes <node> workload=database
kubectl label nodes <node> workload=cache
```
---
## 🔥 常见问题
### 节点无法加入?
```bash
# 检查网络
ping 134.195.210.237
telnet 134.195.210.237 6443
# 查看日志
sudo journalctl -u k3s-agent -f
```
### 节点 NotReady
```bash
# 重启服务
sudo systemctl restart k3s-agent
# 检查详情
kubectl describe node <node-name>
```
### 删除节点
```bash
# 在 Master 节点
kubectl drain <node-name> --ignore-daemonsets
kubectl delete node <node-name>
# 在要删除的节点
sudo /usr/local/bin/k3s-agent-uninstall.sh
```
---
## 📚 详细文档
- 完整扩展指南: [K3S-CLUSTER-EXPANSION.md](K3S-CLUSTER-EXPANSION.md)
- GitOps 自动部署: [README.md](README.md)
---
## 🎯 推荐流程
### 2节点扩展开发环境
1. ✅ 准备 2 台新 VPS
2. ✅ 执行 `join-worker.sh`
3. ✅ 验证节点状态
4. ✅ 测试应用部署
### 4节点扩展生产环境
1. ✅ 配置外部负载均衡器
2. ✅ 转换第一个节点为 HA 模式
3. ✅ 加入 2 个 Master 节点
4. ✅ 加入 4 个 Worker 节点
5. ✅ 配置 Longhorn 多副本
6. ✅ 测试高可用
### 6节点扩展大规模
1. ✅ 同 4 节点方案
2. ✅ 按功能分层部署
3. ✅ 配置节点亲和性
4. ✅ 优化资源分配
---
**快速帮助**: 遇到问题?运行 `bash scripts/check-node-health.sh` 进行诊断