kubernetes Pod(java应用程序)无法与文档数据库通信
我正在尝试在aws eks(kubernetes)集群上运行java应用程序。在成功从gitlab注册表中提取映像后,它尝试启动,但过了一段时间它就停止了。我在问为什么mongodb uri中的主机名没有正确设置为变量${db_host}。下面是容器的日志kubernetes Pod(java应用程序)无法与文档数据库通信,java,mongodb,amazon-web-services,docker,kubernetes,Java,Mongodb,Amazon Web Services,Docker,Kubernetes,我正在尝试在aws eks(kubernetes)集群上运行java应用程序。在成功从gitlab注册表中提取映像后,它尝试启动,但过了一段时间它就停止了。我在问为什么mongodb uri中的主机名没有正确设置为变量${db_host}。下面是容器的日志 2020-05-05 13:50:02.520 INFO 1 --- [ main] c.t.s.java-app.Application : Starting Application on java-app-t
2020-05-05 13:50:02.520 INFO 1 --- [ main] c.t.s.java-app.Application : Starting Application on java-app-ttzjk with PID 1 (/home/gradle/app.jar started by root in /home/gradle)
2020-05-05 13:50:02.527 INFO 1 --- [ main] c.t.s.java-app.Application : The following profiles are active: docker
2020-05-05 13:50:04.280 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2020-05-05 13:50:04.418 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 124ms. Found 2 MongoDB repository interfaces.
2020-05-05 13:50:05.923 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'asyncConfig' of type [com.taskforce.security.dependency.configuration.AsyncConfig$$EnhancerBySpringCGLIB$$16fd6daa] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-05 13:50:06.606 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2020-05-05 13:50:06.628 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-05 13:50:06.633 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-05 13:50:06.766 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-05 13:50:06.766 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4093 ms
2020-05-05 13:50:07.736 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[${db_host}:27017], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='rs0'}
2020-05-05 13:50:07.744 INFO 1 --- [ main] org.mongodb.driver.cluster : Adding discovered server ${db_host}:27017 to client view of cluster
2020-05-05 13:50:07.848 INFO 1 --- [{db_host}:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server ${db_host}:27017
com.mongodb.MongoSocketException: ${db_host}: Name or service not known
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211) ~[mongodb-driver-core-3.11.2.jar!/:na]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75) ~[mongodb-driver-core-3.11.2.jar!/:na]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-3.11.2.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-3.11.2.jar!/:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.11.2.jar!/:na]
at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Caused by: java.net.UnknownHostException: ${db_host}: Name or service not known
at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(Unknown Source) ~[na:na]
at java.base/java.net.InetAddress.getAddressesFromNameService(Unknown Source) ~[na:na]
at java.base/java.net.InetAddress$NameServiceAddresses.get(Unknown Source) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(Unknown Source) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(Unknown Source) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(Unknown Source) ~[na:na]
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-3.11.2.jar!/:na]
... 5 common frames omitted
这是yaml代码。它在本地有效,但在kubernetes上不幸无效
debug: false
server.port: 9000
logging:
level:
root: INFO
org.springframework.web: INFO
org.springframework.boot.autoconfigure: INFO
spring:
devtools.livereload.enabled: false
boot:
admin:
client:
enabled: true
instance:
name: "xxxxxx-xxxxxx"
datasource:
continue-on-error: true
data:
mongodb:
database: xxxxxxxxxx-xxxxxx
uri: "mongodb://xxxxxxxx:xxxxxx@xxxxxxxxxxxxxxxxxxx.docdb.amazonaws.com:27017/xxxxxx-xxxxxxx?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
app:
scheduler:
threadPoolSize: 0
async:
threadPoolSize: 0
这回答了你的问题吗?不是真的!容器正在本地运行,但aws kubernetes上没有运行。当我键入kubectl get pods时,我看到CrashLoopBackOff——所有名称空间都正确设置了环境变量吗?可以发布部署对象吗?您是否将
db\u host
作为环境变量传递给容器?应用程序代码或部署配置中的${db\u host}
出现在哪里?这是否回答了您的问题?不是真的!容器正在本地运行,但aws kubernetes上没有运行。当我键入kubectl get pods时,我看到CrashLoopBackOff——所有名称空间都正确设置了环境变量吗?可以发布部署对象吗?是否将db\u host
作为环境变量传递给容器?在应用程序代码或部署配置中,${db\u host}
出现在哪里?