While running Minikube, I want to connect to a server that has the annoying habit of announcing itself to a service registry with its internal IP address from inside its pod.
However for legacy reasons I have to connect to this registry first and retrieve that server's ip address from it. The only way to access this server from my dev machine, it seems to me, is bridging to the internal network, so I can access the networking of the Minikube. Is there an easy way to do this?
You can add a route to the k8 internal network from localhost
Add a route to the internal network using the minikube ip address
$ sudo ip route add 172.17.0.0/16 via $(minikube ip) # linux
$ sudo route -n add 172.17.0.0/16 $(minikube ip) # OSX
your subnet mask could be found using kubectl get service
command
Test the route by deploying a test container and connect to it from localhost
$ kubectl run monolith --image=kelseyhightower/monolith:1.0.0 --port=80
$ IP=$(kubectl get pod -l run=monolith -o jsonpath='{.items[0].status.podIP }')
$ curl http://$IP
{"message":"Hello"}
You can also add a route to K8 master
sudo route -n add 10.0.0.0/24 $(minikube ip)
This is only useful for local development, you should use NodePort
or LoadBalancer
for exposing pods in production.