<p>I am trying to access a web api deployed into my local Kubernetes cluster running on my laptop (Docker -> Settings -> Enable Kubernetes). The below is my Pod Spec YAML.</p>

<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: test-api
  labels:
    app: test-api
spec:
  containers:
  - name: testapicontainer
    image: myprivaterepo/testapi:latest
    ports:
    - name: web
      hostPort: 55555
      containerPort: 80      
      protocol: TCP
</code></pre>

<p><code>kubectl get pods</code> shows the test-api running. However, when I try to connect to it using <a href="http://localhost:55555/testapi/index" rel="nofollow noreferrer">http://localhost:55555/testapi/index</a> from my laptop, I do not get a response. But, I can access the application from a container in a different pod within the cluster (I did a kubectl exec -it to a different container), using the URL </p>

<blockquote>
  <p>http://<em>test-api pod cluster IP</em>/testapi/index</p>
</blockquote>

<p>. Why cannot I access the application using the localhost:hostport URL?</p>

<p>I'd say that this is strongly not recommended.
According to k8s docs: <a href="https://kubernetes.io/docs/concepts/configuration/overview/#services" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/overview/#services</a></p>
<blockquote>
<p>Don't specify a hostPort for a Pod unless it is absolutely necessary. When you bind a Pod to a hostPort, it limits the number of places the Pod can be scheduled, because each &lt;hostIP, hostPort, protocol&gt; combination must be unique. If you don't specify the hostIP and protocol explicitly, Kubernetes will use 0.0.0.0 as the default hostIP and TCP as the default protocol.</p>
</blockquote>
<blockquote>
<p>If you only need access to the port for debugging purposes, you can use the apiserver proxy or kubectl port-forward.</p>
</blockquote>
<blockquote>
<p>If you explicitly need to expose a Pod's port on the node, consider using a NodePort Service before resorting to hostPort.</p>
</blockquote>
<p>So... Is the hostPort really necessary on your case? Or a NodePort Service would solve it?</p>
<p>If it is really necessary , then you could try using the IP that is returning from the command:</p>
<p><code>kubectl get nodes -o wide</code></p>
<p>http://<strong>ip-from-the-command</strong>:55555/testapi/index</p>
<p>Also, another test that may help your troubleshoot is checking if your app is accessible on the Pod IP.</p>
<p><strong>UPDATE</strong></p>
<p>I've done some tests locally and understood better what the documentation is trying to explain. Let me go through my test:</p>
<ul>
<li>First I've created a Pod with <code>hostPort: 55555</code>, I've done that with a simple nginx.</li>
<li>Then I've listed my Pods and saw that this one was running on one of my specific Nodes.</li>
<li>Afterwards I've tried to access the Pod in the port 55555 through my master node IP and other node IP without success, but when trying to access through the Node IP where this Pod was actually running, it worked.</li>
</ul>
<p>So, the &quot;issue&quot; (and actually that's why this approach is not recommended), is that the Pod is accessible only through that specific Node IP. If it restarts and start in a different Node, the IP will also change.</p>
