<p>I separate a meteor app to be 2 containers: app and node. In the world of docker, the app can connect to the node successfully, but in kubernetes, I have difficulties.</p>

<p>My idea is first launching mongodb and creating the mongodb service, and then creating the app to connect the mongodb service, but I am not sure how to let app use MONGO_URL to connect to service's clusterIP.</p>

<p>So, I have a app-deployement showing bellow,</p>

<pre><code>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
</code></pre>

<p>The service is described as bellow,</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
 name: mongo
 labels:
  name: mongo
spec:
 ports:
  - port: 27017
    targetPort: 27017
 clusterIP: None
 selector:
  app: mongo
</code></pre>

<p>Any ideas are appreciated.</p>

Yu Fang
<p>If the mongodb and mycloud are in the same namespace, then you can use <code>http://mongodb:27017</code></p>

<p>If they are in different namespaces then you can use FQDN <code>http://mongodb.namespace.svc.cluster.local:27017</code></p>

<p>Refer: <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/</a></p>
