You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS EKS 1.25集群中Anchore Pod无法连接PostgreSQL服务的排查求助

AWS EKS 1.25集群中Anchore Pod无法连接PostgreSQL服务的排查求助

大家好,我刚学习Kubernetes大概2个月,现在遇到了一个棘手的问题,希望能得到大家的指点!

环境背景

  • 运行的是AWS EKS 1.25集群
  • 通过Helm Chart部署了Anchore应用,并且把容器镜像改成从自己的AWS ECR仓库拉取(原先是Docker Hub)

问题现象

Anchore的部分Pod日志显示无法解析PostgreSQL服务的主机名,数据库连接失败:

[MainThread] 2023-04-30T00:06:41.155167 [anchore_enterprise_manager.util.db/connect_database()] [INFO] DB attempting to connect...
[MainThread] 2023-04-30T00:06:41.156165 [anchore_enterprise_manager.util.db/connect_database()] [WARN] DB connection failed, retrying - exception: test connection failed - exception: (psycopg2.OperationalError) could not translate host name "postgresql.anchore.svc.cluster.local:5432" to address: Name or service not known

同时还有部分Pod的就绪/存活探针持续失败:

Warning BackOff 17m (x5347 over 43h) kubelet Back-off restarting failed container
Warning Unhealthy 7m26s (x13887 over 43h) kubelet Readiness probe failed: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (7) Failed to connect to localhost port 8089: Connection refused
Warning Unhealthy 2m30s (x14341 over 43h) kubelet Readiness probe failed: Get "http://10.1.1.67:8668/health": dial tcp 10.1.1.67:8668: connect: connection refused

已完成的排查步骤

  1. 检查PostgreSQL服务与端点状态

    • 服务运行正常:
      ➜  ~ k get service postgres-postgresql
      NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
      postgres-postgresql   ClusterIP   172.20.191.83           5432/TCP   27h
      
    • 端点已正确关联Pod:
      ➜  ~ k get endpoints postgres-postgresql
      NAME                  ENDPOINTS        AGE
      postgres-postgresql   10.1.0.74:5432   27h
      
  2. 验证PostgreSQL Pod运行状态

    • Pod日志显示数据库已就绪接收连接:
      k logs postgres-postgresql-59468ff768-zhn6z
      Defaulted container "postgresql" out of: postgresql, postgres-postgresql
      PostgreSQL Database directory appears to contain a database; Skipping initialization
      2023-04-30 14:52:22.289 UTC [1] LOG:  starting PostgreSQL 14.6 (Debian 14.6-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
      2023-04-30 14:52:22.289 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
      2023-04-30 14:52:22.289 UTC [1] LOG:  listening on IPv6 address "::", port 5432
      2023-04-30 14:52:22.292 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
      2023-04-30 14:52:22.296 UTC [27] LOG:  database system was shut down at 2023-04-30 14:52:21 UTC
      2023-04-30 14:52:22.300 UTC [1] LOG:  database system is ready to accept connections
      
  3. 确认服务选择器与Pod标签匹配

    • 服务的选择器为:app=postgresql,release=postgres
    • 通过k describe pods验证,Pod的标签完全匹配上述选择器
  4. 验证集群DNS功能

    • 部署Busybox Pod后,成功解析PostgreSQL服务的主机名:
      ➜  anchore git:(main) ✗ k exec -it busybox-pod -- nslookup postgresql.anchore.svc.cluster.local
      Server:     172.20.0.10
      Address:    172.20.0.10:53
      Name:   postgresql.anchore.svc.cluster.local
      Address: 172.20.191.83
      
  5. 网络相关检查

    • AWS安全组已设置为允许集群节点间的所有流量
    • 确认集群未使用任何网络策略,IPtables也没有阻塞流量
    • CoreDNS组件运行正常
  6. 其他尝试

    • 重新启动Anchore和PostgreSQL的Deployment、Pod及Service
    • 删除Pod强制重新创建
    • 检查所有组件的日志和事件,未发现异常线索

我已经做了这些排查,但还是没找到问题根源,会不会是我忽略了什么明显的细节?如果需要其他信息,我随时可以提供,麻烦大家帮我看看!

备注:内容来源于stack exchange,提问作者Freddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 16:02:56