kubernetes - 从 Kubernetes Pod 访问 SQL Server 数据库

标签 kubernetes kubernetes-pod kubernetes-service kubernetes-deployment kubernetes-cluster

我部署的 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

关于kubernetes - 从 Kubernetes Pod 访问 SQL Server 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57830490/

相关文章:

kubernetes - 成功完成后Kubernetes Pod可以过期吗?

kubernetes - 有没有办法查询 Prometheus 来统计时间范围内失败的作业?

kubernetes Autoscaler - 无法获取 loadbalancing.googleapis.com|https|request_count

kubernetes - 无服务和回滚支持yaml的StatefulSet

kubernetes - 使用 nginx 反向代理公开 Kubernetes 中的服务

kubernetes - 如何显式定义 Kubernetes 服务的端点

kubernetes - 容器优化的OS性能

docker - Kubernetes 节点设备端口 (USB) 映射到 POD?或者Swarm服务--设备映射

kubernetes - 使用容器中的应用程序公开的REST API进行水平Pod自动缩放

kubernetes - Kubernetes 中的 ClusterIP、NodePort 和 LoadBalancer 服务类型有什么区别?