我需要连接到kubernetes集群外部的mongodb。当我一直在互联网上搜索时,我不知道该怎么做,因为我发现了有关如何连接到K8s集群内的mongodb的所有信息。另一方面,我不会反对。但是对于项目的开始,我必须连接到外部mongodb。
你知道怎么做吗?还是您有什么信息可以帮助我?
deployment.yaml:
- name: XXXX_CONFIG_API_MONGODB
value: "mongodb://@IP:27017"
预先感谢
you need to update service not in deployment .its service related issue.
apiVersion: v1
kind: Service
metadata:
name: mongod-db-service
spec:
selector:
app: mongod-db
ports:
- port: 27017
targetPort: 27017
type: LoadBalancer
Note:- "mongod-db" is kubernetes selector that should be same in deployment.
我需要连接到kubernetes集群外部的mongodb。
K8s允许在群集外部访问一些服务方法(即hostNetwork
,hostPort
,NodePort
,LoadBalancer
,Ingress
)
[[本文]迄今为止是主题最佳的文章之一。
通常,您只需要创建一个指向mongodb的服务即可。
它可以是(但不限于)之一:
LoadBalancer
类型: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
NodePort
类型: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
还有更多方法可以实现(只是不想在我一直在指的文章中复制粘贴)。
希望有所帮助。