简体   繁体   中英

Access host resources from a kubernetes cluster service when minikube started with DOCKER vm driver

I have been able to successfully provision services inside a kubernetes minikube cluster to connect to services such as cassandra, kafka, etc installed on the host machine so far when I started the minikube cluster with the virutalbox vm.

minikube start --driver=virtualbox

For this I had to defined k8s manifest say fror cassandra endpoint with an IP address of the host machine identified from within the minikube cluster via following command as suggested here :

minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"

But when I start the minikube cluster with docker as VM driver, I am not able to figure out the ip address of the host machine as identified from inside the cluster because the command to fetch the same doesn't work.

minikube start --driver=docker

minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"
bash: route: command not found

Please suggest how could this ip address be retrived?

I think you overcomplicate things when it is not needed. Since you want to run a testing environment (minikube suggests that) you should always want to start minikube with:

minikube start --driver=docker

Now the IP address of the Kubernetes cluster can be found simply by typing:

minikube ip

Or:

kubectl cluster-info | grep master

This command will show you the ip address that Kubernetes is running from, and the port (usually 6443).

Unfortunately it is not possible to it that way while using Docker as a driver due to the limitations of Docker VM.

There is a workaround listed here , saying:

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST

The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.

The gateway is also reachable as gateway.docker.internal.

But there is no official analogical way to do so with Minikube.

I know that it might not be the exact thing you wanted but I see three options as a workaround:

I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM