📅 撰写日期: 2026-02-10 | 修改日期: 2026-02-13 | ⏱️ 阅读时间: 约 20 分钟
EKS 故障诊断与响应指南
📌 参考环境: EKS 1.30+, kubectl 1.30+, AWS CLI v2
1. 概述
EKS 运维中出现的问题涵盖多个层面,包括 Control Plane、Node、网络、工作负载、存储和可观测性。本文档是一份综合调试指南,旨在帮助 SRE、DevOps 工程师和平台团队系统性地诊断并快速解决这些问题。
所有命令和示例均可直接执行,同时提供了 Decision Tree 和流程图以便快速决策。
EKS 调试层级
调试方法论
诊断 EKS 问题有两种方法。
| 方法 | 描述 | 适用场景 |
|---|---|---|
| 自顶向下(症状 → 原因) | 从用户报告的症状出发,逐步追溯到根本原因 | 服务中断或性能下降等即时事件响应 |
| 自底向上(基础设施 → 应用) | 从基础设施层开始逐层向上检查 | 预防性检查、迁移后验证 |
推荐的一般方法
对于生产环境事件,推荐使用自顶向下方法。首先识别症状(第 2 节 - 事件分类),然后导航到该层级对应的调试章节。
2. 事件分类(快速故障评估)
前 5 分钟检查清单
当事件发生时,最重要的操作是范围识别和初始响应。
30 秒:初始诊断
# Check cluster status
aws eks describe-cluster --name <cluster-name> --query 'cluster.status' --output text
# Check node status
kubectl get nodes
# Check unhealthy Pods
kubectl get pods --all-namespaces | grep -v Running | grep -v Completed
2 分钟:范围识别
# Check recent events (all namespaces)
kubectl get events --all-namespaces --sort-by='.lastTimestamp' | tail -20
# Aggregate Pod status in a specific namespace
kubectl get pods -n <namespace> --no-headers | awk '{print $2}' | sort | uniq -c | sort -rn
# Check distribution of unhealthy Pods by node
kubectl get pods --all-namespaces -o wide --field-selector=status.phase!=Running | \
awk 'NR>1 {print $8}' | sort | uniq -c | sort -rn
5 分钟:初始响应
# Detailed information for the problematic Pod
kubectl describe pod <pod-name> -n <namespace>
# Previous container logs (for CrashLoopBackOff)
kubectl logs <pod-name> -n <namespace> --previous
# Check resource usage
kubectl top nodes
kubectl top pods -n <namespace> --sort-by=cpu
范围识别决策树
AZ 故障检测
AWS Health API 要求
aws health describe-events API 需要 AWS Business 或 Enterprise Support 计划。如果您没有 Support 计划,请直接查看 AWS Health Dashboard 控制台,或创建 EventBridge 规则来捕获 Health 事件。
# Check AWS Health API for EKS/EC2 events (requires Business/Enterprise Support plan)
aws health describe-events \
--filter '{"services":["EKS","EC2"],"eventStatusCodes":["open"]}' \
--region us-east-1
# Alternative: Detect AZ failures without a Support plan — create EventBridge rule
aws events put-rule \
--name "aws-health-eks-events" \
--event-pattern '{
"source": ["aws.health"],
"detail-type": ["AWS Health Event"],
"detail": {
"service": ["EKS", "EC2"],
"eventTypeCategory": ["issue"]
}
}'
# Aggregate unhealthy Pods by AZ (only pods scheduled to a node)
kubectl get pods --all-namespaces -o json | jq -r '
.items[] |
select(.status.phase != "Running" and .status.phase != "Succeeded") |
select(.spec.nodeName != null) |
.spec.nodeName
' | sort -u | while read node; do
zone=$(kubectl get node "$node" -o jsonpath='{.metadata.labels.topology\.kubernetes\.io/zone}' 2>/dev/null)
[ -n "$zone" ] && echo "$zone"
done | sort | uniq -c | sort -rn
# Check ARC Zonal Shift status
aws arc-zonal-shift list-zonal-shifts \
--resource-identifier arn:aws:eks:region:account:cluster/name
使用 ARC Zonal Shift 进行 AZ 故障响应
# Enable Zonal Shift on EKS
aws eks update-cluster-config \
--name <cluster-name> \
--zonal-shift-config enabled=true
# Start manual Zonal Shift (move traffic away from impaired AZ)
aws arc-zonal-shift start-zonal-shift \
--resource-identifier arn:aws:eks:region:account:cluster/name \
--away-from us-east-1a \
--expires-in 3h \
--comment "AZ impairment detected"
Zonal Shift 注意事项
Zonal Shift 的最大持续时间为 3 天,可以延长。一旦启动 Shift,流向受影响 AZ 中 Node 上运行的 Pod 的新流量将被阻断,因此在执行前请确认其他 AZ 中有足够的容量。
Zonal Shift 仅阻断流量
ARC Zonal Shift 仅在 Load Balancer / Service 层面更改流量路由。
⚡ ARC Zonal Shift 영향 범위
Zonal Shift는 트래픽 라우팅만 변경합니다 — 각 계층별 영향 확인