[英]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.到目前为止,当我使用 virutalbox vm 启动 minikube 集群时,我已经能够在 kubernetes minikube 集群内成功配置服务,以连接到安装在主机上的 cassandra、kafka 等服务。
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 :为此,我必须定义 k8s 清单,例如 cassandra 端点,其中主机的 IP 地址通过以下命令从 minikube 集群中识别出来,如下所示:
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.但是,当我使用 docker 作为 VM 驱动程序启动 minikube 集群时,我无法从集群内部找出主机的 ip 地址,因为获取该地址的命令不起作用。
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?请建议如何检索这个 ip 地址?
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 建议),你应该总是想用以下方式启动 minikube:
minikube start --driver=docker
Now the IP address of the Kubernetes cluster can be found simply by typing:现在只需键入以下内容即可找到 Kubernetes 集群的 IP 地址:
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).此命令将向您显示 Kubernetes 正在运行的 ip 地址,以及端口(通常为 6443)。
Unfortunately it is not possible to it that way while using Docker as a driver due to the limitations of Docker VM.不幸的是,由于 Docker VM 的限制,在使用 Docker 作为驱动程序时不可能这样做。
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).
主机有一个不断变化的 IP 地址(如果您没有网络访问权限,则没有)。 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.
从 18.03 开始,我们的建议是连接到特殊的 DNS 名称 host.docker.internal,它解析为主机使用的内部 IP 地址。 This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.
这是出于开发目的,不适用于 Docker Desktop for Mac 之外的生产环境。
The gateway is also reachable as gateway.docker.internal.
网关也可以通过 gateway.docker.internal 访问。
But there is no official analogical way to do so with Minikube.但是对于 Minikube,没有官方的类比方式。
I know that it might not be the exact thing you wanted but I see three options as a workaround:我知道这可能不是您想要的确切内容,但我认为三个选项可以作为解决方法:
Try using Telepresence as a proxy.尝试使用Telepresence作为代理。
Try Routing an internal Kubernetes IP address to the host system .尝试将内部 Kubernetes IP 地址路由到主机系统。
I hope it helps.我希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.