<p>I have a very simple setup. I'm running Kubernetes using the Docker Desktop Kubernetes feature on my PC.</p>
<ol>
<li>There are 2 pods running from the yaml:</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: my-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx:alpine
</code></pre>
<ol>
<li><p>There is another pod running from the command: <code>kubectl run nginx-standalone --image nginx:alpine</code></p>
</li>
<li><p>There is a service from yaml:</p>
</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
 name: nginx-nodeport
spec:
 type: NodePort
 selector:
    app: my-nginx
 ports:
 - port: 80
   targetPort: 80
   nodePort: 31000
</code></pre>
<p>Basically, the service is &quot;connected&quot; only to the pods that come from yaml deployment, due to labels selector.</p>
<p>What I'm doing:</p>
<ol>
<li>I &quot;ssh&quot; into nginx-standalone</li>
<li>I installed curl (inside  of nginx-standalone)</li>
<li>I tried the following (inside  of nginx-standalone):
<ol>
<li><code>curl nginx-nodeport</code> - works well, I get the proper response</li>
<li><code>curl nginx-nodeport:31000</code> - does not work, I get <code>curl: (7) Failed to connect to nginx-nodeport port 31000: Connection refused</code></li>
</ol>
</li>
</ol>
<p>I do not understand why the 2nd command does not return a successful HTTP response. I know that the <code>31000</code> port works, because I can do <code>curl nginx-nodeport:31000</code> from my host PC. Why it does not work from the nginx-standalone pod?</p>

mnj
<p>That's expected behavior because the <code>nodePort</code> <code>31000</code> is listening on the nodes network interface and does not exist in pod's network interface. If you want to access a pod from another pod via kubernetes service use <code>clusterIP</code> type service instead of <code>NodePort</code> type. <code>NodePort</code> type service should be used for exposing a kubernetes pod to consumers outside the kubernetes cluster.</p>
