I'm using minikube with hyperkit
driver, and I need to access a port opened on the host machine FROM a pod inside the minikube cluster.
There are 2 ways I can accomplish this:
Port forward of my local port to the minikube ip
:
ssh -i $(minikube ssh-key) docker@$(minikube ip) -R 8080:localhost:8080
And then from the pod I can curl 172.17.0.1:8080
source: https://medium.com/tarkalabs/proxying-services-into-minikube-8355db0065fd
From my host machine, I get the minikube's bridge IP: ifconfig bridge100
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 8e:85:90:2d:d5:64
inet 192.168.64.1 netmask 0xffffff00 broadcast 192.168.64.255
And then from the pod I can curl 192.168.64.1:8080
However, I'm not sure both methods are the right way. Is there a way to statically reference the host machine to be able to access open ports. What's the solution here?
There are too many layers of indirection involved here and you’ll have to inject the physical host’s IP address into the container as an environment variable or ConfigMap setting. An ExternalName type Service could also work here.
The essential problem here is that each layer can find out about the layer immediately beyond it, but no further. You have a host running a VM running a Kubernetes Pod. The Pod can use the downward API to find its Node’s IP address, but in your case that will be the VM and not the host around it.
(As a parallel question: you have an ordinary home router that’s 192.168.1.1, and your local system is 192.168.1.2. You’re running some server on the router. Meanwhile, you have a VM running on your local system, which sees the host as 172.17.0.1 and believes it is 172.17.0.2. How does the VM reach the service on the router, if it doesn’t know about the 192.168.1.0/24 network in its local network environment?)