简体   繁体   English

pid 1中的java.net.UnknownHostException用于由kube-dns解析的地址

[英]java.net.UnknownHostException in pid 1 for address resolved by kube-dns

I am receiving an java.net.UnknownHostException: postgres-service on a machine where I can ping postgres-service on the command line. 我在可以在命令行上ping postgres-service的机器上收到java.net.UnknownHostException: postgres-service This is in the context of Kubernetes (more specifically GKE) services and Docker images. 这是在Kubernetes(更具体地说是GKE)服务和Docker映像的上下文中。 Could it be that Java requires additional packages (in comparison to ping ) to be installed before it can resolve symbolic IP addresses such as postgres-service ? 难道Java可以解析符号IP地址(例如postgres-service )之前需要安装其他软件包(与ping相比)? I meanwhile guess the answer is no, and that the problem lies with resolving postgres-service via kube-dns is this particular situation (see UPDATE). 我同时猜测答案是否定的,问题出在这种特殊情况下,就是通过kube-dns解决postgres-service (请参阅UPDATE)。

UPDATE The evidence (including the stacktrace below) suggests that the exception is triggered when Tomcat 9 tries to set-up a JDBC realm with connectionURL="jdbc:postgresql://postgres-service/mydb" . 更新证据(包括下面的stacktrace)表明,当Tomcat 9尝试使用connectionURL="jdbc:postgresql://postgres-service/mydb"设置JDBC领域时,将触发异常。 The URL is configured in the context descriptor of a web app, which runs inside a Docker image derived from tomcat:9 . 该URL是在Web应用程序的上下文描述符中配置的,该描述符在从tomcat:9派生的Docker映像中运行。 The context descriptor is generated by a script configured as the image's ENTRYPOINT , which also starts Tomcat (just like the original tomcat:9 does), ie the last few lines of the Dockerfile look as follows: 上下文描述符由配置为映像的ENTRYPOINT的脚本生成,该脚本也启动了Tomcat(就像原始的tomcat:9一样),即Dockerfile的最后几行如下所示:

COPY tomcat-entrypoint.sh /
ENTRYPOINT [ "/tomcat-entrypoint.sh" ]
CMD ["catalina.sh", "run"]

I can ping postgres-service after entering a shell with kubectl exec -it <image> bash . 在使用kubectl exec -it <image> bash进入shell之后,我可以ping postgres-service Could it be that Tomcat (when run as the image's "single process" with pid 1 by way of the Dockerfile's CMD ) sees a different DNS configuration than bash that runs at its sibling? 可能是Tomcat(当通过Dockerfile的CMD与pid 1作为映像的“单个进程”运行时)看到的DNS配置与与其兄弟运行的bash不同吗? The actual DNS configuration employs kube-dns , as is apparent from /etc/resonf.conf . /etc/resonf.conf可以明显看出,实际的DNS配置使用kube-dns

org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
    at org.postgresql.Driver.makeConnection(Driver.java:407)
    at org.postgresql.Driver.connect(Driver.java:275)
    at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:661)
    at org.apache.catalina.realm.JDBCRealm.startInternal(JDBCRealm.java:724)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5054)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: postgres-service
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:64)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:150)
    ... 19 more

I had been using a VM instance without scope compute-rw for development so far (see here ). 到目前为止,我一直在使用没有作用域compute-rw的VM实例进行开发(请参阅此处 )。 I've now recreated it including that scope and rebuilt all relevant Docker images there. 我现在重新创建了包括该范围的对象,并在那里重建了所有相关的Docker映像。 Apparently this has resolved the issue. 显然,这已经解决了问题。

UPDATE There was also a second issue in that I had clusterIP: None as part of the service specification of postgres-service (now gone). 更新还有第二个问题,就是我有clusterIP: None postgres-service服务规范的一部分(现在不存在)。 It beats me why I was still able to ping postgres-service from another pod in the same cluster. 为什么我仍然能够从同一集群中的另一个Pod ping postgres-service我感到ping postgres-service

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

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