I have Google cloud MySQL instance. This is how I'm trying to connect to the DB:
hibernate.hbm2ddl.auto=update
spring.datasource.driver=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://${host}:3306/${database_name}
spring.datasource.username=username
spring.datasource.password=password
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=false
When I run Spring-boot locally (Either as standalone application, or in Docker container), it works as expected and I'm able to connect to google instance. But once I deploy it as k8 pod to google k8 cluster, I get this error:
2021-05-29T10:58:53.509609037Zcom.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
Info
2021-05-29T10:58:53.509624634ZThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Info
2021-05-29T10:58:53.509634325Z at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509641816Z at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509650943Z at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509660187Z at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509667583Z at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509674049Z at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.509681366Z at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.509689163Z at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[na:1.8.0_212]
2021-05-29T10:58:53.509695511Z at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:155) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509711714Z at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:146) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509718794Z at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509725553Z at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509732733Z at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509740924Z at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509749641Z at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509756783Z at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509763753Z at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509770623Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509796702Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509802689Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509808731Z at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509815653Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509822479Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509829318Z at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509843010Z at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509849856Z at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509856595Z at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509863586Z at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) [hibernate-core-5.4.30.Final.jar!/:5.4.30.Final]
Info
2021-05-29T10:58:53.509872075Z at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.3.5.jar!/:5.3.5]
Info
2021-05-29T10:58:53.509878468Z at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.3.5.jar!/:5.3.5]
Info
2021-05-29T10:58:53.509884538Z at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:40
Info
2021-05-29T10:58:53.509905668Z at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) [spring-orm-5.3.5.jar!/:5.3.5]
Info
2021-05-29T10:58:53.509914159Z at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.3.5.jar!/:5.3.5]
Info
2021-05-29T10:58:53.509920884Z at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509927455Z at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509933694Z at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509939206Z at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509945426Z at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509959520Z at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509966550Z at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509973044Z at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509982819Z at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.509989186Z at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[
2021-05-29T10:58:53.509995584Z at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
Info
2021-05-29T10:58:53.510004994Z at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510011525Z at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510018006Z at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510023845Z at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510033258Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510039845Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510046040Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
Info
2021-05-29T10:58:53.510052673Z at com.alekseytyan.logiweb.LogiwebService.main(LogiwebService.java:9) ~[classes!/:1.0-SNAPSHOT]
Info
2021-05-29T10:58:53.510060800Z at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510067072Z at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510073383Z at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510079940Z at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
2021-05-29T10:58:53.510086547Z at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[logiweb-service.war:1.0-SNAPSHOT]
Info
2021-05-29T10:58:53.510092467Z at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) ~[logiweb-service.war:1.0-SNAPSHOT]
Info
2021-05-29T10:58:53.510098016Z at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[logiweb-service.war:1.0-SNAPSHOT]
Info
2021-05-29T10:58:53.510105920Z at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59) ~[logiweb-service.war:1.0-SNAPSHOT]
Info
2021-05-29T10:58:53.510113410ZCaused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Info
2021-05-29T10:58:53.510126973ZThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Info
2021-05-29T10:58:53.510154628Z at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510162460Z at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510179730Z at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
Info
2021-05-29T10:58:53.510187599Z at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
2021-05-29T10:58:53.510194600Z at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510200781Z at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510207172Z at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510214725Z at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510221716Z at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510228880Z at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510236037Z at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510242239Z at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
Info
2021-05-29T10:58:53.510248946Z ... 57 common frames omitted
Info
2021-05-29T10:58:53.510255264ZCaused by: java.net.ConnectException: Operation timed out (Connection timed out) at java.net.PlainSocketImpl.socketConnect(Native Method) ~
I was thinking it concerns stuff with external access and IPs, but it's just my assumpsions