[英]How to connect mongodb service by MONGO_URL when the db service is clusterIP?
我將流星應用程序分為兩個容器:應用程序和節點。 在docker世界中,該應用程序可以成功連接到節點,但是在kubernetes中,我遇到了困難。
我的想法是先啟動mongodb並創建mongodb服務,然后創建應用程序以連接mongodb服務,但是我不確定如何讓應用程序使用MONGO_URL連接到服務的clusterIP。
所以,我有一個應用程序部署顯示波紋管,
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: app
name: mycloud
spec:
replicas: 1
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
containers:
- name: app
image: yufang/cloud_docker_app
ports:
- containerPort: 3000
env:
- name: MONGO_URL
value: mongodb://localhost:27017/meteor # here comes the key point. How to specify the service's ip? or use the selector to specify the service's label?
- name: PORT
value: "3000"
- name: ROOT_URL
value: http://localhost
該服務被描述為波紋管,
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
app: mongo
任何想法表示贊賞。
如果mongodb和mycloud在同一名稱空間中,則可以使用http://mongodb:27017
如果它們在不同的命名空間中,則可以使用FQDN http://mongodb.namespace.svc.cluster.local:27017
請參閱: https : //kubernetes.io/docs/concepts/services-networking/connect-applications-service/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.