<p>I'm pretty new to Kubernetes, I have docker for mac, not minikube.</p>
<p>I have the deployment file running with one pod (containing an express app) in the cluster, then i created a NodePort service.</p>
<p>Inside the express app i have a get request to '/posts' and I want to access it from the localhost.</p>
<p>i have this service file here:</p>
<p><a href="https://i.stack.imgur.com/nZXWY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nZXWY.png" alt="enter image description here" /></a></p>
<p>However, when i'm trying to access my localhost in the port that is given to the NodePort service,
for example localhost:30134/posts,
i get page isn't working on Chrome.</p>
<p>Anyone has an idea why?</p>

Dannom
<p>PREMISE:</p>
<blockquote>
<p>Every node in the cluster configures itself to listen on that assigned port and to forward traffic to one of the ready endpoints associated with that Service. You'll be able to contact the type: NodePort Service, from outside the cluster, by connecting to any node using the appropriate protocol (for example: TCP), and the appropriate port (as assigned to that Service).</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport</a></p>
<p>First you should figure out what node the &quot;posts&quot; pod is running on.</p>
<pre><code>kubectl -n NAMESPACE get pods -owide | grep -i posts
</code></pre>
<p>Once you figure out which node it's running on, retrieve its INTERNAL-IP:</p>
<pre><code>kubectl get nodes -owide
</code></pre>
<p>After that you will be able to reach the node via Browser (NODE-INTERNAL-IP:NODEPORT-PORT).</p>
<p>If you absolutely want to reach the service via &quot;localhost&quot; name, add the entry in the /etc/hosts file.</p>
<p>For example:</p>
<pre><code>echo &quot;127.0.0.1 NODE-INTERNAL-IP&quot; &gt;&gt; /etc/hosts
</code></pre>
