A few years ago, I wrote an essay about this topic titled “How to Access Host Resources in Minikube Pods?”. In it, I have described how to access host resources in Minikube. Something I thought should be easy but, at the time, it really wasn’t.
Back then, I’ve described an approach, based on a Github issue, relying on listing kernel routing tables, that allowed us to fetch the IP of the host machine inside Minikube. I described why this worked, going so far as sharing a few snippets of code from the Kubernetes source code.
While this has served me well for the last few years, I’ve recently discovered that this approach is a bit outdated - the documentation on that essay doesn’t even exist anymore. I wrote this when Minikube was v1.6.2 and it is now v1.23.1…a lot has happened. After searching a bit more, I’ve understood that Minikube now has a proper solution for this, documented in Host access.
This approach applies for Minikube bigger than v1.10 and it essentially relies on using
host.minikube.internal in order to connect to the host Minikube is running on. According to the documentation, “minikube v1.10 adds a hostname entry host.minikube.internal to /etc/hosts.” I’ve tested this and it seems to actually work, while being much easier and reliable.
As with the initial approach, the same caveat applies:
The service running on your host must either be bound to all IP’s (0.0.0.0) and interfaces, or to the IP and interface your VM is bridged against. If the service is bound only to localhost (127.0.0.1), this will not work.