I am trying to connect my spring-boot api inside a kubernetes pod to an external database (a separate machine but within the local network), however when running, I get SQLNonTransientConnectionException, UknownHostException: mysql-svc, the api cannot connect to the database but whenever I ping the database address from inside the pod using kubectl exec -it, I can ping it successfully, anybody who has experienced the same error as mine?
here is my application.properties connection uri and kubernetes objects:
why would you need to create a service for a mysql server that’s outside of the kubernetes cluster? just provide the ip or the endpoint, i don’t think you do a service as that setups an ip inside the k cluster right?
If the database is external to the cluster, then m the service type cluster IP won’t help. That will try to match pods inside the cluster (there are none, as it is an external db).
You can use the IP to try to connect and make sure this works. Once this works, we can follow up with improvements. But let’s get started with the basic
Good day…
Have you got solution for this issue…? Am also trying to connect external oracle database in spring boot application deployed in kubernetes container. I created a service to connect the external oracle database and am able ping the oracle server inside the kubernetes container. But Application is not able to connect the oracle server and throwing socket time out exception.
Please help here to proceed.? thanks much.
root@tomcat-springboot-pks-stateful-0:/# ping oracle-server-hostname
PING oracle-server-hostname (----ip----------) 56(84) bytes of data.
64 bytes from ----ip---------- (----ip----------): icmp_seq=1 ttl=49 time=31.5 ms
64 bytes from ----ip---------- (----ip----------): icmp_seq=2 ttl=49 time=30.9 ms
64 bytes from ----ip---------- (----ip----------): icmp_seq=3 ttl=49 time=31.0 ms
64 bytes from ----ip---------- (----ip----------): icmp_seq=4 ttl=49 time=31.1 ms
Kubernetes Pod Logs
18:16:18.405 [http-nio-8092-exec-5] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out] with root cause
oracle.net.ns.NetException: Socket read timed out
at oracle.net.ns.Packet.receive(Packet.java:350)
at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:159)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
Yes… I found… I created the external service for the oracle database server and connected with the springboot application with service name and it works…
kind: Service
apiVersion: v1
metadata:
name: /** oracle server name which is configured in springboot application.yml file … Ex - oracleserver /
spec:
type: ExternalName
externalName: / oracle hostname. Ex - oracleserver.xx.yyy.com **/
I am trying to connect my external oracle database from the container using Proc C. I did the same step, it is not connecting getting tns destination host unreachable. Could any one help on this.
To connect my app to the external db
## Is this service right for my app?
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- name: http
protocol: TCP
port: 80
targetPort: 9376 ## the port of the pod can be the same as that of the external db ?? ?
externalIPs:
- 80.11.12.10 ## can it be the ip of the db ???