Skip to content

Health 检查失败

错误信息

                Health 检查失败: HTTP 503 Service Unavailable
              

快速摘要

health 检查端点返回非-200 响应, 所以加载 balancer or orchestrator 停止发送 traffic 到 service.

为什么发生

  • application 是 overloaded and cannot respond 到 health 检查 in 时间

  • health 检查端点有 bug or 是不 implemented 正确地

  • dependency (数据库, 缓存) 是下, and health 检查 reports 它

  • health 检查 timeout 是也 短 for 响应时间

最小示例

✗ 错误代码
livenessProbe:
  httpGet:
    path: /health
    port: 8080
  timeoutSeconds: 1  # too short
✓ 修复代码
livenessProbe:
  httpGet:
    path: /health
    port: 8080
  timeoutSeconds: 5  # more realistic

health 检查 timeout 是也 短 (1s), causing failures under 加载. fix increases 它到 5 seconds.

如何诊断

  • Call health 端点 directly: curl http://<host>/health

  • 检查 application logs for 错误围绕 health 检查

  • 验证 health 检查配置 (path, port, timeout)

  • 测试如果 dependencies 是 available and responding

如何修复

  • Fix application 错误那个 causes health 检查到 失败

  • Increase health 检查 timeout or interval

  • Fix or 重启 dependency 那个 health 检查 depends on

  • Ensure health 端点返回 200 当 service 是 healthy

如何预防

  • Keep health 检查 lightweight — 做不 执行 expensive 操作

  • 设置 appropriate timeouts based on expected 响应次数

  • Monitor health 检查失败速率 and alert on trends

相关资源

← 返回语言