简体   繁体   English

Kubernetes 服务无法发现外部名称

[英]Kubernetes service with external name not discoverable

I'm deploying a nodejs application into a kubernetes cluster.我正在将 nodejs 应用程序部署到 kubernetes 集群中。 This application needs access to an external database which is public available under db.external-service.com .此应用程序需要访问db.external-service.com下公共可用的外部数据库。 For this purpose a service of the type ExternalName is created.为此,创建了ExternalName类型的服务。

kind: Service
apiVersion: v1
metadata:
  name: postgres
spec:
  type: ExternalName
  externalName: db.external-service.com

In the deployment an environment variable which provides the database hostname for the application is set to the name of this service.在部署中,为应用程序提供数据库主机名的环境变量设置为此服务的名称。

env:
  - name: DB_HOST
    value: postgres

The problem is that when the nodejs application try to connect to the database ends up with this error message.问题是,当 nodejs 应用程序尝试连接到数据库时,会出现此错误消息。

Error: getaddrinfo ENOTFOUND postgres

Already tried to use the full hostname postgres.<my-namespace>.svc.cluster.local without success.已经尝试使用完整的主机名postgres.<my-namespace>.svc.cluster.local但没有成功。

What cloud be wrong with this setup?这个设置有什么问题?

EDIT:编辑:

  • It works if I use directly the plain ip address behind db.external-service.com in my pod configuration如果我在我的 pod 配置中直接使用db.external-service.com后面的普通 ip 地址,它就可以工作
  • It dose not work if I use the hostname directly in my pod configuration如果我直接在我的 pod 配置中使用主机名,它不起作用
  • I can ping the hostname with one of my pods: kubectl exec my-pod-xxx -- ping db.external-service.com has the right ip address我可以用我的一个 pod ping 主机名: kubectl exec my-pod-xxx -- ping db.external-service.com有正确的 ip 地址

It turns out that the Kubernetes worker nodes are not on the allow list from the database.事实证明,Kubernetes 工作节点不在数据库的允许列表中。 So the connection timed out.所以连接超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM