Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Kubernetes集群外部连接到Mongodb_Mongodb_Kubernetes_Google Kubernetes Engine_Kubernetes Helm_Kubectl - Fatal编程技术网

如何从Kubernetes集群外部连接到Mongodb

如何从Kubernetes集群外部连接到Mongodb,mongodb,kubernetes,google-kubernetes-engine,kubernetes-helm,kubectl,Mongodb,Kubernetes,Google Kubernetes Engine,Kubernetes Helm,Kubectl,我需要连接到kubernetes集群的mongodb外部。我不知道怎么做,当我一直在互联网上搜索时,我在K8s集群中找到了关于如何连接到mongodb的所有信息。另一方面,我也不会反对。但是对于项目的开始,我必须连接到外部mongodb 你知道怎么做吗?或者你有什么信息谁能帮我 deployment.yaml: - name: XXXX_CONFIG_API_MONGODB value: "mongodb://@IP:27017" 提前感谢您需要更新未部署的服务。这是与服务相关的问

我需要连接到kubernetes集群的mongodb外部。我不知道怎么做,当我一直在互联网上搜索时,我在K8s集群中找到了关于如何连接到mongodb的所有信息。另一方面,我也不会反对。但是对于项目的开始,我必须连接到外部mongodb

你知道怎么做吗?或者你有什么信息谁能帮我

deployment.yaml:

  - name: XXXX_CONFIG_API_MONGODB
    value: "mongodb://@IP:27017"

提前感谢

您需要更新未部署的服务。这是与服务相关的问题

apiVersion: v1
kind: Service
metadata:
  name: mongod-db-service
spec:
  selector:
    app: mongod-db
  ports:
    - port: 27017
      targetPort: 27017
  type: LoadBalancer
注意:-“mongod db”是kubernetes选择器,在部署中应该相同

我需要连接到kubernetes集群的mongodb外部

K8s允许在集群外部访问一些服务方法(即
主机网络
主机端口
节点端口
负载平衡器
入口

到目前为止,这是一个最好的话题

通常,您只需要创建一个指向mongodb的服务

可以是(但不限于):

  • 负载平衡器
    类型:
  • 节点端口
    类型:
有更多的方法可以实现这一点(只是不想在这里复制粘贴我所指的文章)


希望能有所帮助。

为您的MongoDB Pod公开一个NodePort服务,然后使用节点的公共IP作为主机。您成功连接了吗?我必须在deployment.yaml文件中执行一些操作?没有。创建连接到部署的服务。检查:-
kind: Service 
apiVersion: v1 
metadata: 
  name: mongo 
spec: 
  type: LoadBalancer 
  ports: 
    - port: 27017 
  selector: 
    app: my-mongo-db  # this shall match labels from the Deployment
apiVersion: v1
kind: Service
metadata:
  name: mongo
spec:
  selector:
    app: my-mongo-db
  type: NodePort
  ports:
    - 
      port: 27017
      nodePort: 30001 # al the incoming connections to NodeIP:30001 will be forwarded to your mongo-pod