如何将 Minikube 集群暴露到互联网

sam*_*ulé 7 networking kubernetes minikube

我知道 minikube 应该仅用于本地,但我想为我的应用程序创建一个测试环境。
为了做到这一点,我希望将 minikube 集群内运行的应用程序公开给外部访问(从公共互联网上的任何设备 - 例如 4G 智能手机)。

注意:我运行 minikube--driver=docker

kubectl 获取服务

NAME      TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
web8080   NodePort   10.99.39.162   <none>        8080:31613/TCP   3d1h
Run Code Online (Sandbox Code Playgroud)

迷你库贝 IP

192.168.49.2
Run Code Online (Sandbox Code Playgroud)

一种方法如下:

firewall-cmd --add-port=8081/tcp
kubectl port-forward --address 0.0.0.0 services/web8080 8081:8080
Run Code Online (Sandbox Code Playgroud)

然后我可以使用以下方式访问它:

curl localhost:8081      (directly from the machine running the cluster inside a VM)
curl 192.168.x.xx:8081   (from my Mac in same network - this is the private ip of the machine running the cluster inside a VM)
curl 84.xxx.xxx.xxx:8081 (from a phone connected in 4G - this is the public ip exposed by my router)
Run Code Online (Sandbox Code Playgroud)

我不想使用此解决方案,因为kubectl port-forward它很弱并且每次端口转发不再活动时都需要运行。

我怎样才能做到这一点?

(已编辑)-使用负载均衡器

当使用LoadBalancertype 和时minikube tunnel,我只能在运行集群的机器内部公开服务。

kubectl 获取服务

NAME         TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
my-service   LoadBalancer   10.111.61.218   10.111.61.218   8080:31831/TCP   3d3h
Run Code Online (Sandbox Code Playgroud)

curl 10.111.61.218:8080(在运行集群的机器内)正在工作
,但curl 192.168.x.xx:8080(在同一 LAN 上的我的 Mac 上)不工作

谢谢

Daw*_*ruk 4

Minikube作为单节点 Kubernetes 集群的开发工具,在 Kubernetes 和外部设备之间提供了固有的隔离层(具体是从/到集群的入站流量)。LANWAN

不同的--drivers在涉及 Kubernetes 集群生成的位置及其网络行为方式方面提供了灵活性。

附注(解决方法)!

由于您minikube已经驻留在 a 中VM并使用--driver=docker您可以尝试使用--driver=none(您将能够curl VM_IP:NodePortLAN)。它将直接在VM.

考虑检查它的文档,因为有一些特定的限制/缺点:


由于此设置已经基于VM(具有未知的虚拟机管理程序)并且集群旨在暴露在 LAN 之外,因此我建议您使用生产就绪设置。这将从本质上消除您面临的连接问题。Kubernetes 集群将直接在容器上配置VM,而不是在Docker容器中。

解释一下--driver=docker使用的内容:它将在主机系统上生成一个容器,其中包含 Kubernetes。该容器内部Docker将再次用于生成Pods运行 Kubernetes 集群所需的资源。

至于配置 Kubernetes 集群的工具,您需要选择最适合您需求的选项。其中一些如下:

在 a 上创建 Kubernetes 集群后,VM您可以将流量从路由器直接转发到您的VM.


您可能会发现有用的其他资源: