How ingress controller is providing dns names?

4/17/2020

I am trying to understand how ingress controller works in kubernetes.

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

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

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

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

I have used ngrok for this

ngrok http foo.localhost

but it points to nginx default page and not my app

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

-- piby180
kubernetes
kubernetes-ingress
nginx
nginx-ingress
ngrok

1 Answer

4/17/2020

On your machine, localhost and foo.localhost 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 Host header with the ngrok URL, which is not the same as foo.localhost, so the ingress thinks the request is for a different domain.

Try exposing your localhost in the ingress using the ngrok url.

-- Burak Serdar
Source: StackOverflow