feat: add check_events.sh, check_resources.sh, check_all.sh for diagnostics

This commit is contained in:
2026-04-01 17:10:03 +08:00
parent 2793bce239
commit 18bce33a1e
3 changed files with 116 additions and 0 deletions

36
cluster/check_events.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# 用途:檢查叢集事件(診斷問題最重要!)
set -euo pipefail
# 顏色定義
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "=========================================="
echo " K3s 叢集事件 (最近1小時)"
echo "=========================================="
echo ""
# 顯示最近 1 小時的 Warning 和 Error 事件
echo "⚠️ Warning / Error 事件"
echo "------------------------------------------"
kubectl get events -A --sort-by='.lastTimestamp' --field-selector type!=Normal | \
grep -E "(Warning|Error)" | tail -20 || echo "無異常事件"
echo ""
echo "📋 所有最近事件 (最近20筆)"
echo "------------------------------------------"
kubectl get events -A --sort-by='.lastTimestamp' | tail -20
echo ""
echo "🔄 計畫失敗的 Pod"
echo "------------------------------------------"
kubectl get pods -A | grep -E "(Failed|Error|CrashLoopBackOff|ImagePullBackOff)" || echo -e "${GREEN}無異常 Pod${NC}"
echo ""
echo "=========================================="
echo "提示: 事件太多可用 kubectl get events -A --field-selector type=Warning"
echo "=========================================="