dotnet core pod in Kubernetes connect to SQL Server that outside cluster

1,217 views
Skip to first unread message

Peeradis Sa-nguantrakul

unread,
Oct 3, 2018, 9:27:01 AM10/3/18
to Kubernetes developer/contributor discussion

I have a dotnet core pod in Kubernetes(minikube) that need to access to Host(on the same computer but not in kubernetes cluster) 

SQL Server(Testing Server). it work in the container but when i put it in to pod. it can't find sql server on my machine

but i can ping from pod to my SQL Server

here is the error from log


  1. An error occurred using the connection to database
  2. > 'ArcadiaAuthenServiceDB' on server '192.168.2.68'.
  3. > System.Data.SqlClient.SqlException (0x80131904): A network-related or
  4. > instance-specific error occurred while establishing a connection to
  5. > SQL Server. The server was not found or was not accessible. Verify
  6. > that the instance name is correct and that SQL Server is configured to
  7. > allow remote connections. (provider: TCP Provider, error: 40 - Could
  8. > not open a connection to SQL Server)
ping
  1. root@authenservice-dpm-57455f59cf-7rqvz:/app# ping 192.168.2.68
  2. PING 192.168.2.68 (192.168.2.68) 56(84) bytes of data.
  3. 64 bytes from 192.168.2.68: icmp_seq=1 ttl=127 time=0.449 ms
  4. 64 bytes from 192.168.2.68: icmp_seq=2 ttl=127 time=0.361 ms
  5. 64 bytes from 192.168.2.68: icmp_seq=3 ttl=127 time=0.323 ms
  6. 64 bytes from 192.168.2.68: icmp_seq=4 ttl=127 time=0.342 ms
  7. ^C
  8. --- 192.168.2.68 ping statistics ---
  9. 4 packets transmitted, 4 received, 0% packet loss, time 3064ms
  10. rtt min/avg/max/mdev = 0.323/0.368/0.449/0.053 ms
  11. root@authenservice-dpm-57455f59cf-7rqvz:/app#

my Connection String in Container
  1. "DefaultConnection": "Server=192.168.2.68; Database=ArcadiaAuthenServiceDB; MultipleActiveResultSets=true;User Id=pbts;Password=pbts"

I try to Created Service End-point in Kubernetes but no luck.

here the service.yml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: mssql-s
  5. namespace: default
  6. spec:
  7. ports:
  8. - port: 1433
  9. ---
  10. apiVersion: v1
  11. kind: Endpoints
  12. metadata:
  13. name: mssql-s
  14. namespace: default
  15. subsets:
  16. - addresses:
  17. - ip: 192.168.2.68
  18. ports:
  19. - port: 1433 
  20. –--

  21. Thank you.

Brendan Burns

unread,
Oct 3, 2018, 11:05:35 AM10/3/18
to Kubernetes developer/contributor discussion, Peeradis Sa-nguantrakul
My guess is that SQL server is serving on localhost (127.0.0.1) not all interfaces (0.0.0.0).

I would stand up a simple web server on your machine serving on all interfaces and try to curl from the pod to that web server. If that works it's definitely the SQL server configuration.

--brendan


From: kuberne...@googlegroups.com <kuberne...@googlegroups.com> on behalf of Peeradis Sa-nguantrakul <deadm...@gmail.com>
Sent: Wednesday, October 3, 2018 1:14:22 AM
To: Kubernetes developer/contributor discussion
Subject: dotnet core pod in Kubernetes connect to SQL Server that outside cluster
 
--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/2c79bc99-1ee0-440a-bd47-ea3964f72a60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deep Sukhwani

unread,
Oct 3, 2018, 11:25:38 AM10/3/18
to bbu...@microsoft.com, kuberne...@googlegroups.com, deadm...@gmail.com
If the narrowed down issue is that mysql is bound to work only with loopback (127.0.0.1), the change to allow it on all IP Address goes in /etc/local/my.cnf (on Linux) or /usr/local/etc/my.cnf on OS X environment (Essentially it goes in your MySQL cnf - default named as my.cnf file).


--
Regards
Deep L Sukhwani


Brendan Burns

unread,
Oct 3, 2018, 11:26:32 AM10/3/18
to Deep Sukhwani, kuberne...@googlegroups.com, deadm...@gmail.com
Note that I think the original request was about SQL server on Linux not MySQL, so the configuration will be similar but in a different place.

--brendan


From: Deep Sukhwani <deepsu...@gmail.com>
Sent: Wednesday, October 3, 2018 8:22:10 AM
To: Brendan Burns
Cc: kuberne...@googlegroups.com; deadm...@gmail.com
Subject: Re: dotnet core pod in Kubernetes connect to SQL Server that outside cluster
 

Peeradis Sa-nguantrakul

unread,
Oct 3, 2018, 9:45:45 PM10/3/18
to Kubernetes developer/contributor discussion
Edit

I go investigate more and find out that it not k8s problem.
It about SQL Server and Firewall Rule Inbound Setting.
Once i set it up. it working now.

Thank you every one for reply.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages