我部署的 Spring boot 应用程序尝试从 Kubernetes Pod 连接到外部 SQL Server 数据库。但每次都会失败并出现错误

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.

我尝试执行 Pod 并成功 ping 数据库服务器,没有任何问题

以下是我尝试过的解决方案:

  1. 创建了服务和端点,并在配置文件中提供了数据库 IP,尝试在 Pod 中启动应用程序

  2. 尝试在配置中使用端点的内部 IP 而不是数据库 IP,以查看内部 IP 是否解析为数据库 IP

但这两种情况都给出了相同的结果。下面是我用来创建服务和端点的 yaml。

--- 
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 

如果我的设置有误或遗漏,请告诉我。

K8s 设置的其他信息

  • 它是具有外部 etcd 集群拓扑的集群主服务器
  • 节点上的操作系统是 CentOS
  • 能够从所有节点和创建的 Pod ping 服务器

请您参考如下方法:

对于这种情况, headless 服务非常有用。您将把流量重定向到该 IP,而无需定义端点。

kind: "Service" 
apiVersion: "v1" 
metadata: 
  namespace: "your-namespace" 
  name: "ftp" 
spec: 
  type: ExternalName 
  externalName: your-ip 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!