<p>I'm using ansible script to deploy streamsets on k8s master node. There is play where I'm checking if the streamset dashboard is accessible via <em><a href="http://127.0.0.1" rel="nofollow noreferrer">http://127.0.0.1</a>:{{streamsets_nodePort}}</em> where <code>streamsets_nodePort: 30029</code>. The default port is 30024, which is assigned to other service, so I've changed the port.</p>

<p>The service is Up and the pods are running. </p>

<p><code>NAME                         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE</code></p>

<p><code>service/streamsets-service   NodePort   10.104.162.67   &lt;none&gt;        18630:30029/TCP   24m</code></p>

<p>When do see the logs I can see, 
<code>Running on URI : 'http://streamsets-0.streamsets-service.streamsets-ns.svc.cluster.local:18630'</code>
<code>2020-04-30 13:45:58,149 [user:] [pipeline:] [runner:] [thread:main] [stage:] INFO  WebServerTask -</code> <code>Running on URI : 'http://streamsets-0.streamsets-service.streamsets-ns.svc.cluster.local:18630'</code></p>

<p>The below is my service.yml </p>

<p><code>apiVersion: v1
kind: Service
metadata:
  name: streamsets-service
  labels:
    name: streamsets
spec:
  type: NodePort
  ports:
  - port: {{streamsets_port}}
    targetPort: 18630
    nodePort: {{streamsets_nodePort}}
  selector:
    role: streamsets</code></p>

<p>These are the assigned port details: </p>

<p><code>streamsets_port: 8630</code></p>

<p><code>streamsets_nodePort: 30029</code></p>

<p><code>streamsets_targetPort: 18630</code></p>

<p>In my play when I'm executing the below block </p>

<pre><code>`- name: Check if Streamsets is accessible.`
  `uri:`
    `url: http://localhost:{{streamsets_nodePort}}`
    `method: GET`
    `status_code: 200`
  `register: streamsets_url_status`

- debug:`
    `var: streamsets_url_status.msg`
</code></pre>

<p>The output I'm getting while executing this block - </p>

<p><code>fatal: [127.0.0.1]: FAILED! =&gt; {"changed": false, "content": "", "elapsed": 30, "msg": "Status code was -1 and not [200]: Connection failure: timed out", "redirected": false, "status": -1, "url": "http://localhost:30029"}</code></p>

<p><strong>Can someone help me to understand what is the issue?</strong> </p>

Shuvodeep Ghosh
<p>Perhaps I'm not understanding correctly, but why would the service be responsive on the localhost IP of <code>127.0.0.1</code>?</p>

<p>You're creating a NodePort mapping, which automatically creates a ClusterIP - you can see that in your services listing: <code>10.104.162.67</code>
That IP is the one that should be used to access the application whose port you've exposed with the service, in combination with the 'port' specification you've made (8630 in this case).</p>

<p>Alternatively, if you wanted to directly access the NodePort you created then you would hit the direct internal-IP of the node(s) on which the pod is running. Execute a <code>kubectl get nodes -o wide</code> and note the internal IP address of the Node you're interested in, and then make a call against that IP address in combination with the nodePort you've specified for the service (30029 in this case).</p>

<p>Depending on which layer you're SSH-ing/exec-ing into (pod, node, conatiner, etc.) the resolution for 127.0.0.1 could be completely different - a container you've exec'd into doesn't resolve 127.0.0.1 to the address of the host it's running on, but rather resolves to the pod it's running in.</p>
