2

My deployed Spring boot application to trying to connect to an external SQL Server database from Kubernetes Pod. But every time it fails with error

Failed to initialize pool: The TCP/IP connection to the host <>, port 1443 has failed.
Error: "Connection timed out: no further information.
Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.

I have tried to exec into the Pod and successfully ping the DB server without any issues

Below are the solutions I have tried:

  1. Created a Service and Endpoint and provided the DB IP in configuration file tried to bring up the application in the Pod

  2. Tried using the Internal IP from Endpoint instead of DB IP in configuration to see Internal IP is resolved to DB IP

But both these cases gave the same result. Below is the yaml I am using the create the Service and Endpoint.

---
apiVersion: v1
kind: Service
metadata:
  name: mssql
  namespace: cattle
spec:
  type: ClusterIP
  ports:
  - port: 1433
---
apiVersion: v1
kind: Endpoints
metadata:
  name: mssql
  namespace: cattle
subsets:
- addresses:
  - ip: <<DB IP>>
  ports:
  - port: 1433

Please let me know if I am wrong or missing in this setup.

Additional information the K8s setup

  • It is clustered master with external etcd cluster topology
  • OS on the nodes is CentOS
  • Able to ping the server from all nodes and the pods that are created
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sujith Shajee
  • 175
  • 5
  • 18
  • Looking at the error message, it looks like the application does not know the hostname for the database. It is printing out an empty hostname. – Burak Serdar Sep 07 '19 at 03:50
  • @bserdar there is DB IP in the error msg. I think it was missed when I copied the msg out – Sujith Shajee Sep 07 '19 at 03:55
  • You might want to check if you can communicate with the db itself from the pods, maybe using a command line client for the db? Or maybe even simple curl to the host:port? Maybe the db ports are blocked. Also, you can simply connect to the name "mssql" without the IP. – Burak Serdar Sep 07 '19 at 04:02
  • Are you able to `telnet` to the DB server? (`telnet 3306`) – Sagar Chilukuri Sep 07 '19 at 04:54

2 Answers2

3

For this scenario a headless service is very useful. You will redirect traffic to this ip without defining an endpoint.

kind: "Service"
apiVersion: "v1"
metadata:
  namespace: "your-namespace"
  name: "ftp"
spec:
  type: ExternalName
  externalName: your-ip
Rodrigo Loza
  • 1,200
  • 7
  • 14
2

The issue was resolved by updating the deployment yaml with IP address. Since all the servers were in same subnet, I did not need the to create a service or endpoint to access the DB. Thank you for all the inputs on the post

Sujith Shajee
  • 175
  • 5
  • 18