Kubernetes 中的 dotnet 核心 pod 连接到本地 SQL 服务器
dotnet core pod in Kubernetes connect to local SQL Server
我在 Kubernetes(minikube) 中有一个 dotnet 核心 pod,需要访问本地 SQL 服务器(测试服务器)。
它在容器中工作,但当我将它放入 pod 时。它无法在我的机器上运行 sql 服务器
但我可以从 pod ping 到我的 SQL 服务器
这是日志中的错误
An error occurred using the connection to database
> 'ArcadiaAuthenServiceDB' on server '192.168.2.68'.
> System.Data.SqlClient.SqlException (0x80131904): A network-related or
> instance-specific error occurred while establishing a connection to
> SQL Server. The server was not found or was not accessible. Verify
> that the instance name is correct and that SQL Server is configured to
> allow remote connections. (provider: TCP Provider, error: 40 - Could
> not open a connection to SQL Server)
平
root@authenservice-dpm-57455f59cf-7rqvz:/app# ping 192.168.2.68
PING 192.168.2.68 (192.168.2.68) 56(84) bytes of data.
64 bytes from 192.168.2.68: icmp_seq=1 ttl=127 time=0.449 ms
64 bytes from 192.168.2.68: icmp_seq=2 ttl=127 time=0.361 ms
64 bytes from 192.168.2.68: icmp_seq=3 ttl=127 time=0.323 ms
64 bytes from 192.168.2.68: icmp_seq=4 ttl=127 time=0.342 ms
^C
--- 192.168.2.68 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3064ms
rtt min/avg/max/mdev = 0.323/0.368/0.449/0.053 ms
root@authenservice-dpm-57455f59cf-7rqvz:/app#
容器中的我的连接字符串
"DefaultConnection": "Server=mssql-s; Database=ArcadiaAuthenServiceDB; MultipleActiveResultSets=true;User Id=pbts;Password=pbts"
我尝试在 Kubernetes 中创建服务端点,但没有成功。
谢谢。
编辑
这里 Service.yml 文件
apiVersion: v1
kind: Service
metadata:
name: mssql-s
namespace: default spec:
ports:
- port: 1433
---
apiVersion: v1
kind: Endpoints
metadata:
name: mssql-s
namespace: default subsets:
- addresses:
- ip: 192.168.2.68
ports:
- port: 1433
–--
编辑
我检查 SQL 服务器也在监听 1433
PS C:\Windows\system32> netstat -aon | findstr 1433
TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING 5028
TCP [::]:1433 [::]:0 LISTENING 5028
有什么办法可以解决这个问题吗?
感谢您的所有回复。
今天我找到了解决方案。它与 k8s 无关,而与防火墙设置有关。
我添加入站规则以允许端口 1433。并且它
我在 Kubernetes(minikube) 中有一个 dotnet 核心 pod,需要访问本地 SQL 服务器(测试服务器)。 它在容器中工作,但当我将它放入 pod 时。它无法在我的机器上运行 sql 服务器
但我可以从 pod ping 到我的 SQL 服务器
这是日志中的错误
An error occurred using the connection to database
> 'ArcadiaAuthenServiceDB' on server '192.168.2.68'.
> System.Data.SqlClient.SqlException (0x80131904): A network-related or
> instance-specific error occurred while establishing a connection to
> SQL Server. The server was not found or was not accessible. Verify
> that the instance name is correct and that SQL Server is configured to
> allow remote connections. (provider: TCP Provider, error: 40 - Could
> not open a connection to SQL Server)
平
root@authenservice-dpm-57455f59cf-7rqvz:/app# ping 192.168.2.68
PING 192.168.2.68 (192.168.2.68) 56(84) bytes of data.
64 bytes from 192.168.2.68: icmp_seq=1 ttl=127 time=0.449 ms
64 bytes from 192.168.2.68: icmp_seq=2 ttl=127 time=0.361 ms
64 bytes from 192.168.2.68: icmp_seq=3 ttl=127 time=0.323 ms
64 bytes from 192.168.2.68: icmp_seq=4 ttl=127 time=0.342 ms
^C
--- 192.168.2.68 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3064ms
rtt min/avg/max/mdev = 0.323/0.368/0.449/0.053 ms
root@authenservice-dpm-57455f59cf-7rqvz:/app#
容器中的我的连接字符串
"DefaultConnection": "Server=mssql-s; Database=ArcadiaAuthenServiceDB; MultipleActiveResultSets=true;User Id=pbts;Password=pbts"
我尝试在 Kubernetes 中创建服务端点,但没有成功。
谢谢。
编辑 这里 Service.yml 文件
apiVersion: v1
kind: Service
metadata:
name: mssql-s
namespace: default spec:
ports:
- port: 1433
---
apiVersion: v1
kind: Endpoints
metadata:
name: mssql-s
namespace: default subsets:
- addresses:
- ip: 192.168.2.68
ports:
- port: 1433
–--
编辑 我检查 SQL 服务器也在监听 1433
PS C:\Windows\system32> netstat -aon | findstr 1433
TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING 5028
TCP [::]:1433 [::]:0 LISTENING 5028
有什么办法可以解决这个问题吗?
感谢您的所有回复。 今天我找到了解决方案。它与 k8s 无关,而与防火墙设置有关。 我添加入站规则以允许端口 1433。并且它