#!/bin/bash
# 配置參數
LOG_FILE="/var/log/k8s_troubleshooting.log"
# 檢查并創建日志文件
if [ ! -f "$LOG_FILE" ]; then
touch "$LOG_FILE"
fi
# 記錄日志函數
log() {
echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}
# 檢查節點狀態
log "Checking node status..."
kubectl get nodes -o wide
# 檢查Pod狀態
log "Checking Pod status..."
kubectl get pods --all-namespaces -o wide
# 檢查事件
log "Checking events..."
kubectl describe nodes
kubectl describe pods --all-namespaces
# 檢查日志
log "Checking logs..."
kubectl logs -l app=my-app -n default
log "Troubleshooting completed successfully."