Skip to content

Dependency Unavailable

错误信息

                错误: 失败到 连接到 dependency service
              

快速摘要

application cannot 开始 or 函数因为 service 它 depends on 是不 运行 or reachable.

为什么发生

  • dependency service (数据库, 缓存, 消息 queue) 是不 运行

  • Network issues prevent application 从 reaching dependency

  • dependency service URL or port 是 misconfigured

  • dependency 是 in 不同命名空间 or network and 是不 accessible

最小示例

✗ 错误代码
# App starts before database is ready
spec:
  containers:
    - name: app
      image: myapp  # crashes: DB not ready
✓ 修复代码
# Use init container to wait for DB
spec:
  initContainers:
    - name: wait-for-db
      image: busybox
      command: ['sh', '-c', 'until nslookup db-service; do sleep 2; done']
  containers:
    - name: app
      image: myapp

app crashes 因为数据库是 不 ready. fix 添加 init 容器那个 waits for DB service 到是 available.

如何诊断

  • 检查如果 dependency service 是运行: kubectl 获取 pods -l app=<dependency>

  • 测试 connectivity 从 application Pod: kubectl exec <pod> -- curl <dependency-URL>

  • 验证 dependency URL and port in 配置

  • 检查 Service and NetworkPolicy 配置

如何修复

  • 开始 or 重启 dependency service

  • Fix dependency URL or port in 配置

  • 创建 Service for dependency 如果 one 做不 exist

  • Adjust NetworkPolicies 到允许 traffic 到 dependency

如何预防

  • Use init 容器到 wait for dependencies 之前开始 app

  • Implement graceful degradation 当 dependencies 是 unavailable

  • Monitor dependency health and alert on failures

相关资源

相关术语

← 返回语言