[英]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:编辑:
db.external-service.com
in my pod configuration如果我在我的 pod 配置中直接使用db.external-service.com
后面的普通 ip 地址,它就可以工作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.所以连接超时。
Seems like your Pod is not able to resolve DNS db.external-service.com to an IP Address.似乎您的 Pod 无法将 DNS db.external-service.com 解析为 IP 地址。
In Kubernetes, Pods use CoreDNS Pods to resolve Service Names to Service IP Addresses.在 Kubernetes 中,Pod 使用 CoreDNS Pod 将服务名称解析为服务 IP 地址。 https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/ https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/
If CoreDNS Pods are not able to resolve the DNS to IP Address it is supposed to redirect the request to the Nameserver configured in the Host/VM/Node resolv.conf because dnsPolicy for CoreDNS Pods is Default.如果 CoreDNS Pod 无法将 DNS 解析为 IP 地址,则应该将请求重定向到在 Host/VM/Node resolv.conf 中配置的名称服务器,因为 CoreDNS Pod 的 dnsPolicy 是默认值。 https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
So what is the dnsPolicy of your Pod?那么你的 Pod 的 dnsPolicy 是什么?
Are you able to resolve DNS db.external-service.com to an IP Address from the Host/VM/Node on which the CoreDNS Pod is running on?您能否将 DNS db.external-service.com 从运行 CoreDNS Pod 的主机/VM/节点解析为 IP 地址?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.