#!/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 "=========================================="