<p>In the Minikube , I created a pod with the configuration provided below </p>

<pre><code>kind: Pod
metadata:
  name: node-js-pod
spec:
  containers:
  - name: node-js-pod
    image: bitnami/apache:latest
    ports: 
    - containerPort: 8080 
</code></pre>

<p>then i created a service of type cluster-ip with configuration provided below</p>

<pre><code>kind: Service
metadata:
   name: node-js-internal
   labels:
     name: node-js-internal
spec:
  ports:
  - port: 8081
  selector:
    name: node-js
</code></pre>

<p>After creating the service i checked the cluster ip of service using command:
<code>kubectl get services -l name=node-js-internal</code>
which gave output as:</p>

<pre><code>NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
node-js-internal   ClusterIP   10.106.71.114   &lt;none&gt;        8081/TCP   18m
</code></pre>

<p>Once I created this service i tried to access this service internally from node-js-pod using command:
<code>kubectl exec node-js-pod -- curl 10.106.71.114:8081</code>
Which gave error message as curl 7 connection timed out :</p>

<pre><code>$ kubectl exec node-js-pod -- curl 10.106.71.114:8081
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:02:10 --:--:--     0curl: (7) Failed to connect to 10.106.71.114 port 8081: Connection timed out
command terminated with exit code 7
</code></pre>

<p>How to connect to the node-js-internal service from pod node-js in minikube?</p>

<p>Use the same port in the service as the container is listening to.</p>

<pre><code>kind: Service
metadata:
   name: node-js-internal
   labels:
     name: node-js-internal
spec:
  ports:
  - port: 8080
  selector:
    name: node-js-pod
</code></pre>

<p>If you want to have a different port in the service, than the container is listening to, you need to specify a mapping in the service</p>

<pre><code>ports:
  - protocol: TCP
    port: 8081
    targetPort: 8080
</code></pre>
