I have virtual machine centOS(v7.4) running on Openstack. In virtual machine, I deployed kubernetes and 7 pods, virtual machine could ping the external server. But one pod uaa could NOT connect database on external network (app.xxx.com 11521), and logs say:
... 49 common frames omitted
Caused by: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:39) ~[commons-dbcp2-2.1.1.jar!/:2.1.1]
at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256) ~[commons-dbcp2-2.1.1.jar!/:2.1.1]
at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2304) ~[commons-dbcp2-2.1.1.jar!/:2.1.1]
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2290) ~[commons-dbcp2-2.1.1.jar!/:2.1.1]
... 53 common frames omitted
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:375) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:678) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:238) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
... 61 common frames omitted
Caused by: java.net.UnknownHostException: app.xxx.com: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_111]
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_111]
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_111]
at java.net.InetAddress.getAllByName0(InetAddress.java:1276) ~[na:1.8.0_111]
at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[na:1.8.0_111]
at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[na:1.8.0_111]
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:171) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.net.nt.ConnOption.connect(ConnOption.java:123) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:353) ~[ojdbc6-11.2.0.1.0.jar!/:11.2.0.2.0]
... 66 common frames omitted
I ssh into the pod,
[centos@kube-master ingress2]$ sudo kubectl exec -it gearbox-rack-uaa-service -5b5fd58d87-5zsln -- /bin/bash
root@gearbox-rack-uaa-service-5b5fd58d87-5zsln:/# ping app.xxx.com
ping: unknown host
My questions is how to let pod connects to external database?
in your spec file try setting "spec.template.spec.hostNetwork: true" There are other things this affects but should get over your ping issue