<p>I have mern app which is running on my local host , so how can I deploy this on Kubernetes, which MongoDB URL link is set on backend, and how front end interacts with nodejs api?</p>
<p>i am trying to connect mongodb containers services to node js and nodejs services into react containers.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-server-app-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: todo-server-app
  template:
    metadata:
      labels:
        app: todo-server-app
    spec:
      containers:
        - image: summer07/backend1:1.0
          name: container1
          ports:
            - containerPort: 5000
          imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  name: todo-server-app
spec:
  selector:
    app: backend
  ports:
    - name: http
        port: 80
    targetPort: 5000
    externalTrafficPolicy: Cluster
this is my backend yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
      app: mongo
  replicas: 1
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
        - image: mongo:4.0.9-xenial
          name: container1
          ports:
            - containerPort: 27017
          command:
            - mongod
            - &quot;--bind_ip&quot;
            - &quot;0.0.0.0&quot;
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /data/db
              name: todo-mongo-vol
      volumes:
        - name: todo-mongo-vol
          persistentVolumeClaim:
            claimName: todo-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    app: mongo
spec:
  selector:
    app: mongo
  ports:
    - port: 27017
      targetPort: 27017
</code></pre>
<p>this is mongo yml
i see logs they mongopod is connected with nodejs pod but wen i use minikubeip and node js serive host in brower i am not able to get respone .
i use to connect in mongo with mongo service and port in nodejs backend</p>

Summer
<p>If you deploy the application to Kubernetes, so for Database <strong>MongoDB</strong> you can use the <strong>operator</strong> to manage the <strong>PODs</strong> and <strong>deployment</strong>.</p>
<p>In Kubernetes <strong>services</strong> internally connect with each other using the <strong>Service-name</strong>. Service forward traffic to Deployment which is backed by the <strong>PODs</strong>.</p>
<p>so if you deployed <strong>mongoDb</strong> database there will be <strong>svc</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: mongo
</code></pre>
<p>so it will be something like</p>
<pre><code>const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@mongo:${MONGO_PORT}/${MONGO_DB}?authSource=admin`;
</code></pre>
<p>same goes from <strong>react</strong> to <strong>node js</strong> <strong>service</strong>, service-name is used internally as <strong>DNS</strong>,</p>
<pre><code>curl http://node-service:8080
</code></pre>
<p>you can pass accordingly in your code <strong>node service</strong> as <strong>Host</strong>.</p>
