简体   繁体   English

当 minikube 使用 DOCKER vm 驱动程序启动时,从 kubernetes 集群服务访问主机资源

[英]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:我知道这可能不是您想要的确切内容,但我认为三个选项可以作为解决方法:

I hope it helps.我希望它有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Docker Kubernetes 集群获取 URL 并在没有 Minikube 集群的情况下访问正在运行的服务 - Get URL and access a running service without Minikube Cluster , using a Docker Kubernetes cluster 无法从浏览器访问我的 minikube 集群(❗ 因为你在 windows 上使用了 Docker 驱动程序,所以需要打开终端才能运行它。) - Unable to access my minikube cluster from the browser (❗ Because you are using a Docker driver on windows, the terminal needs to be open to run it.) Kubernetes - docker 驱动程序上的入口 - minikube 1.16 - Kubernetes - Ingress on docker driver - minikube 1.16 如何从本地机器访问 Docker Desktop - minikube 集群? - How to access Docker Desktop - minikube cluster from local machine? 从 docker 容器内访问 Kubernetes 集群 - Access to a kubernetes cluster from inside a docker container 无法从 Mac 上的主机使用 NodePort 访问 minikube 服务 - Can't access minikube service using NodePort from host on Mac 如何使用 docker 驱动访问 Minikube 中的 NodePort? - How to access NodePort in Minikube with docker driver? 如何在启用 MFA 的情况下将 docker 图像从 AWS ECR 拉到 Minikube Kube.netes 集群 - How to pull a docker image from AWS ECR to Minikube Kubernetes cluster with MFA enabled 基于 PC 的多个 VM 和 Docker 容器与 Kubernetes - 超越 minikube - PC based multiple VM & docker containers with Kubernetes - going beyond minikube 如何从VM访问Docker容器中的服务? - Howto access a service in a docker container from VM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM