Files
k3s/QUICKSTART.md

190 lines
2.7 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 叢集 - 快速入門
新手友善的 K3s 維護指南
## 🚀 快速開始
### 連線到叢集
```bash
ssh ubuntu@192.168.42.120
sudo -i
cd /root/k8s
```
---
## 📦 服務管理
### 部署服務
```bash
cd apps/<app-name>/
./deploy.sh
```
例如部署 CodiMD
```bash
cd /root/k8s/apps/codimd
./deploy.sh
```
### 查看服務狀態
```bash
cd apps/<app-name>/
./status.sh
```
輸出包含:
- Pods 狀態
- Services 狀態
- PVC 儲存狀態
- Ingress 入口
- 資料庫連通性(如適用)
### 停止服務(保留資料)
```bash
cd apps/<app-name>/
./stop.sh
```
⚠️ 注意:`stop.sh` 只刪除 Deployment/Service/Ingress**PVC 和 Secret 會保留**
---
## 💾 備份與還原
### 備份服務
```bash
cd apps/<app-name>/
./backup.sh
```
備份位置:
- CodiMD → `apps/codimd/backup/`
- Opengist → `apps/opengist/backup/`
- PostgreSQL → `apps/postgres/backups/`
### 還原服務
```bash
cd apps/<app-name>/
./restore.sh
```
⚠️ 還原前請先停止服務
---
## 🔍 叢集診斷
### 檢查節點狀態
```bash
cd /root/k8s/cluster
./check_nodes.sh
```
### 檢查儲存空間
```bash
cd /root/k8s/cluster
./check_storage.sh
```
### 檢查存取權限
```bash
cd /root/k8s/cluster
./check_access.sh
```
---
## 🛠️ 常見問題排查
### Pod 無法啟動?
```bash
# 查看 Pod 狀態
kubectl get pods
# 查看詳細資訊
kubectl describe pod <pod-name>
# 查看日誌
kubectl logs <pod-name>
```
### 服務無法連線?
```bash
# 檢查 Service
kubectl get svc
# 檢查 Endpoints是否有 Pod 掛上)
kubectl get endpoints <service-name>
# 檢查 Ingress
kubectl get ingress
```
### 儲存空間不足?
```bash
# 檢查 Longhorn volumes
kubectl get pv -A
kubectl get pvc -A
# 檢查節點磁碟
df -h
```
---
## 📝 修改 Manifests
1. **本地編輯**:在 `/Users/timmy/42_120/k8s/` 修改 yaml
2. **同步到遠端**
```bash
rsync -avz --rsync-path="sudo rsync" \
/Users/timmy/42_120/k8s/ \
ubuntu@192.168.42.120:/root/k8s/
```
3. **應用變更**
```bash
cd /root/k8s/apps/<app-name>
kubectl apply -f manifests/
```
---
## 🔄 Git 版控工作流程
```bash
# 本地
cd /Users/timmy/42_120/k8s
git add -A
git commit -m "描述變更"
git push
# 確認遠端已有變更後,再同步到 K3s 主機
```
---
## 📋 服務清單速查
| 服務 | 目錄 | deploy | stop | status | backup |
|------|------|--------|------|--------|--------|
| CodiMD | `apps/codimd/` | ✅ | ✅ | ✅ | ✅ |
| Opengist | `apps/opengist/` | ✅ | ✅ | ✅ | ✅ |
| PostgreSQL | `apps/postgres/` | ✅ | ✅ | ✅ | ✅ |
---
💡 **提示**:執行任何腳本前,先用 `./status.sh` 確認目前狀態!