<p>I am trying to understand how ingress controller works in kubernetes.</p>

<p>I have deployed nginx ingress controller on bare metal k8s cluster (referred to kind ingress docs)
localhost now points to nginx default page.</p>

<p>I have deployed an app with an ingress resource with host as "foo.localhost". 
I can access my app on foo.localhost now.</p>

<p>I would like to know how nginx was able to do it without any modificaion on /etc/hosts file.</p>

<p>I also want to access my app from different machine over same/different network.</p>

<p>I have used ngrok for this</p>

<p><code>ngrok http foo.localhost</code></p>

<p>but it points to nginx default page and not my app</p>

<p>How can I access it using ngrok if I don't want to use port forward or kube proxy.</p>

piby180
<p>On your machine, <code>localhost</code> and <code>foo.localhost</code> all resolve to the same address, 127.0.0.1. This is already there, it is not something nginx or k8s does. That's the reason why you cannot access that from another machine, because that name resolves to the localhost for that machine as well, not the one running your k8s ingress.  When you exposed it using ngrok, it exposes it using a different name. When you try to access the ingress using that name, the request contains a <code>Host</code> header with the ngrok URL, which is not the same as <code>foo.localhost</code>, so the ingress thinks the request is for a different domain.</p>

<p>Try exposing your localhost in the ingress using the ngrok url.</p>
