<p>app-service.yaml</p>

<pre><code>kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  type: NodePort
  ports:
  - name: "5000"
    port: 5000
    targetPort: 5000
    nodePort: 31000
  selector:
    io.kompose.service: app
status:
  loadBalancer: {}
</code></pre>

<p>app-deployment.yaml</p>

<pre><code>kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: app
    spec:
      containers:
      - image: jithinchowdary/todo_app:latest
        name: app
        ports:
        - containerPort: 5000
        resources: {}
      restartPolicy: Always
  selector:
    matchLabels:
      io.kompose.service: app
status: {}
</code></pre>

<p>mongodb-service.yaml</p>

<pre><code>kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb
  name: mongodb
spec:
  ports:
  - name: "27017"
    port: 27017
    targetPort: 27017
  selector:
    io.kompose.service: mongodb
status:
  loadBalancer: {}
</code></pre>

<p>mongodb-deployment.yaml</p>

<pre><code>kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb
  name: mongodb
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: mongodb
    spec:
      containers:
      - image: mongo
        name: mongodb
        ports:
        - containerPort: 27017
        resources: {}
      restartPolicy: Always
  selector:
      matchLabels:
        io.kompose.service: mongodb
status: {}
</code></pre>

<p>used kompose convert to generate the files, docker images are successfully built, server is running properly on port 5000, have entered react app pot and tried to start server got the error of port already in use, which means server is running, still not able to acess the app
not able access on port 31000, express server deployed on 5000, mongo 27017</p>

<pre><code>NAME                          READY   STATUS    RESTARTS   AGE
pod/app-5944bf6886-jz79l      1/1     Running   0          80m
pod/mongodb-847948b5f-2clvp   1/1     Running   0          79m

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/app          NodePort    10.106.129.159   &lt;none&gt;        5000:31000/TCP   80m
service/kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          83m
service/mongodb      ClusterIP   10.107.146.128   &lt;none&gt;        27017/TCP        79m

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/app       1/1     1            1           80m
deployment.apps/mongodb   1/1     1            1           79m

NAME                                DESIRED   CURRENT   READY   AGE
replicaset.apps/app-5944bf6886      1         1         1       80m
replicaset.apps/mongodb-847948b5f   1         1         1       79m

curl 10.106.129.159:5000
ccurl: (7) Failed to connect to 10.106.129.159 port 5000: Operation timed out```

</code></pre>

user3671377
<p>The NodePort here is the port on the host(vm), try <code>&lt;your_host_ip&gt;:31000</code>
NodePort => <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#nodeport</a>
you can also try :5000 to access your service.</p>

<p>If you are using minikube/minishift, the vm ip is the host ip.
If you are running it on a multi node cluster, </p>

<ol>
<li><code>oc get pods -o wide</code> to get the node</li>
<li>then <code>oc get node &lt;node&gt;</code> to get the ip</li>
</ol>

<p>FYI.
1. If you want to expose your api, NodePort is not a good option.
2. don't use "5000" as a service name</p>
