简体   繁体   English

GCP - 从单独的 Kubernetes 集群连接到 VM 实例

[英]GCP - Connect to VM Instance from Separate Kubernetes Cluster

I have a kubernetes cluster that comprises my application and a database that I host on a separate VM instance (outside of the cluster).我有一个 kubernetes 集群,其中包含我的应用程序和我托管在单独 VM 实例(集群外部)上的数据库。 The database should be listening on port 27017 (I confirm this using netstat).数据库应该侦听端口 27017(我使用 netstat 确认了这一点)。 I want to be able for my services in my cluster to connect to this database.我希望集群中的服务能够连接到该数据库。 I recieve errors about the connection timing out.我收到有关连接超时的错误。 This leads me to believe that a) the service discovery in my cluster is not working correctly (most likely a configuration issue) or b) there is some firewall that is blocking my requests.这让我相信 a) 我的集群中的服务发现工作不正常(很可能是配置问题)或 b) 有一些防火墙阻止了我的请求。

To allow my external database to be discovered, I have defined a service and a custom endpoint for my database.为了允许发现我的外部数据库,我为我的数据库定义了一个服务和一个自定义端点。 Here is the service definition:这是服务定义:

kind: Service
apiVersion: v1
metadata:
 name: db-service
 namespace: production
spec:
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017

Here is the endpoint definition:这是端点定义:

kind: Endpoints
apiVersion: v1
metadata:
 name: db-service
 namespace: production
subsets:
 - addresses:
     - ip: <internal-ip>
   ports:
     - port: 27017

I have tried using both the external and internal ips for the endpoint definition (using the internal ip makes the most sense to me).我已经尝试将外部和内部 ip 用于端点定义(使用内部 ip 对我来说最有意义)。

The only network tags I have on my VM instance hosting my database is 'http-server' and 'https-server' (default tags allowing for http/https traffic).我在托管数据库的 VM 实例上拥有的唯一网络标签是“http-server”和“https-server”(允许 http/https 流量的默认标签)。

What in my approach is preventing requests from nodes in my cluster from being received by my db being hosted on the VM instance?我的方法是什么阻止来自我的集群中节点的请求被托管在 VM 实例上的数据库接收?

原来我的数据库没有侦听远程连接(对于 postgresql,请查看 pg_hba.conf 和 postgresql.conf)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM