#!/bin/bash
# 配置参数
LOG_FILE="/var/log/k8s_health_check.log"
# 检查并创建日志文件
if [ ! -f "$LOG_FILE" ]; then
touch "$LOG_FILE"
fi
# 记录日志函数
log() {
echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}
# 检查Kubernetes节点状态
log "Checking Kubernetes node status..."
kubectl get nodes
# 检查Pod状态
log "Checking Pod status..."
kubectl get pods --all-namespaces
# 检查服务状态
log "Checking Service status..."
kubectl get services --all-namespaces
# 检查Deployment状态
log "Checking Deployment status..."
kubectl get deployments --all-namespaces
log "Health check completed successfully."