Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map 'localhost' to minikube with Ingress

I'm using minikube version 1.4.0 and Kubernetes version 1.16.0 on MacOS 10.15.

I'm developing some authorization/authentication code that relies on an external service. In the API calls to the service, I'm required to provide a redirect URL. The URL has to be either 1) a legit FQDN from an external service (when I go to production) or 2) localhost/<whatever>. My code, however, does not use localhost - it uses a custom minikube.local which maps to Minikube's IP (as opposed to 127.0.0.1).

Note - I could use NodePort type Kubernetes services and port-forward them which would, for example, allow me to hit my Django server at localhost:8000. However, I am choosing to use Ingress (so my Minikube environment most closely resembles my production environment) which takes away this ability.

Is there a way to use localhost instead of my Minikube's IP and its associated DNS name?

like image 695
s g Avatar asked Sep 01 '25 20:09

s g


1 Answers

If you want to test your backend is working you can do something like this:

curl -H 'Host: localhost' -v $(minikube ip)

For it to work in the browser you need an ssh tunnel, this one works for me:

ssh -i $(minikube ssh-key) docker@$(minikube ip) -L 8008:localhost:80

This maps port 80 in minikube's cluster to 8008 in localhost. If you want to map port 80 then you will need add sudo, at least for some linux distros.

like image 169
Andres R Avatar answered Sep 04 '25 15:09

Andres R