minikube ip 无法访问

minikube ip is not reachable

我创建了一项名为 fleetman-webapp 的服务:

apiVersion: v1
kind: Service
metadata:
 name: fleetman-webapp

spec:
 selector:
  app: webapp

 ports:
  - name: http
    port: 80
    nodePort: 30080

 type: NodePort

还有一个名为 webapp:

的 pod
apiVersion: v1
kind: Pod
metadata:
 name: webapp
 labels:
  app: webapp
spec:
 containers:
 - name: webapp
   image: richardchesterwood/k8s-fleetman-webapp-angular:release0

我查看了minikube ip:

192.168.99.102

但是当我在浏览器中输入 192.168.99.102:30080 时,webapp 无法访问:

请注意,我使用的是 Ubuntu 最新版本。我进一步验证了代理和防火墙是否处于活动状态:

猫/etc/environment:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

iptables -L:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (1 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere 

我也在Ubuntu中禁用了ufw,但没有成功,url192.168.99.102:30080.

你能帮帮我吗?预先感谢您的回答。

有很多不同的管理程序可以与 minikube 一起工作。选择一个将高度依赖于操作系统等变量。其中一些是:

  • 虚拟盒子
  • 超 V
  • VMware 融合
  • KVM2
  • 超级套件
  • "Docker (--vm-driver=none)"(见引号)

有官方文档在谈论它:Kubernetes.io: Minikube: Specifying the vm driver

选择 Hypervisor 将影响 minikube 的行为方式。

专注于:

  • Docker: --vm-driver=none
  • 虚拟盒子:--vm-driver=virtualbox

Docker

官方文档总结:

Minikube also supports a --vm-driver=none option that runs the Kubernetes components on the host and not in a VM. Using this driver requires Docker and a Linux environment but not a hypervisor.

-- Kubernetes.io: Install minikube: Install a hypervisor

命令$ sudo minikube ip 的输出将显示 主机 的 IP 地址。

NodePort 的服务对象类型将在 IP_ADDRESS_OF_HOST:NODEPORT_PORT 中可用。

跟随命令:$ kubectl get nodes -o wide

NAME STATUS ROLES  AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
K8S  Ready  master 95s v1.17.3 192.168.0.114 <none>  Ubuntu 18.04.4 LTS 5.3.0-28-generic docker://19.3.8

具体请看:

INTERNAL-IP
192.168.0.114

它的 IP 地址与其工作的主机相同。您可以(例如)curl pods 没有任何限制。请考虑阅读包含引用的文章:

Caution: The none VM driver can result in security and data loss issues. Before using --vm-driver=none, consult this documentation for more information.

您可以使用以下命令检查暴露的内容: $ sudo netstat -tulpn

虚拟盒子

使用 --vm-driver=virtualbox 创建 minikube 实例将创建一个以 Virtualbox 作为主机的虚拟机。

使用这种 --vm-driver 创建的虚拟机将具有下面提供的 2 个网络接口:

  • NAT
  • 仅主机适配器

重要的是您的 minikube 实例可以通过 Host-only 适配器 访问。

Host-only networking. This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface, similar to a loopback interface, is created on the host, providing connectivity among virtual machines and the host.

-- Virtualbox.org: Virtual networking

例如:

  • minikube host-only 适配器将有一个地址:192.168.99.103
  • 您的仅主机适配器将有一个地址:192.168.99.1

他们一定不一样!

如果您在连接到此适配器时遇到问题,请检查:

  • minikube start 成功完成时,如果 minikube 的仅主机适配器地址正在响应 ping
  • 您的 host-only 适配器存在于您的网络配置中,方法是发出:
    • ip a
    • ifconfig
  • 您的仅主机适配器地址在您的 minikube 实例(子网)范围内

根据我的经验 reboot/recreation 如果出现问题,此适配器始终可以正常工作。

命令$ sudo minikube ip 的输出将显示Host-only 适配器 的IP 地址。

跟随命令:$ kubectl get nodes -o wide

NAME   STATUS   ROLES    AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE              KERNEL-VERSION   CONTAINER-RUNTIME
m01    Ready    master   29m   v1.17.3   192.168.99.103   <none>        Buildroot 2019.02.9   4.19.94          docker://19.3.6

请具体看一下与之关联的INTERNAL-IPip address

NodePort 的服务对象类型将适用于: IP_ADDRESS_OF_HOST_ONLY_ADAPTER:NODEPORT_PORT

我重新创建了附加到它的 DeploymentService,它在 --vm-driver=none--vm-driver=virtualbox 两种情况下都有效。

如果您对此主题有任何疑问,请告诉我。

即使您在 minikube 中通过 NodePort 公开端口 30080,minikube 仍然不会公开它,因为它将使用自己的外部端口来侦听此服务。 Minikube 通过隧道将服务暴露给外部世界。要找出暴露的端口:

minikube service $SERVICE_NAME

所以,在你的情况下

minikube service fleetman-webapp

对于这个关于 Kubernetes on Udemy from Richard Chesterwood 的特定(并且非常棒)课程,以下解决方案应该在 Windows 上开箱即用:只需从 minikube 开始 hyper-v驱动程序,然后它会自动将您期望的所有端口映射到您的主机上,如 Dawid Kruk 在此处详细解释的那样。因此,您需要“正确”启动 minikube 的是以下命令:

minikube start --driver=hyperv

通过指定您提供给此 minikube 实例的确切内存量来小心。根据我的经验,hyper-v 对您将为其提供多少内存有点敏感,这可能会导致错误:

minikube start --driver=hyperv --memory=8192
...
Not enough memory in the system to start the virtual machine minikube.
Could not initialize memory: Not enough memory resources are available to complete this operation. (0x8007000E).
'minikube' failed to start. (Virtual machine ID D4BC7B61-4E4D-4079-94DE-...)
Not enough memory in the system to start the virtual machine minikube with ram size 8192 megabytes. (Virtual machine ID ...)

因此,只需使用上面给出的非特定命令,hyper-v 就会自己计算出它真正需要多少内存。

我遇到了同样的问题,并且在过去的两天里一直在尝试解决这个问题我尝试安装入口插件:

minikube addons enable ingress

也尝试过 运行 :

minikube tunnel

寻找一种允许主机访问容器 IP 地址的方法,但显然找不到方法。

如果你 运行 minikube 在 docker:

minikube start --driver=docker

您将无法从您的 主机 访问 minikube IP,因为可以通过以下方式访问 minikube 容器的 IP 地址DockerDesktopVM 但不是来自您的主机。

您可以 运行 minikube 在另一个驱动程序上,例如 VirtualBoxHyperv,这可能会有所帮助。

minikube start --driver=hyperv
minikube start --driver=virtualbox

阅读有关 minikube drivers

的更多信息

In fact, that's really annoying if you don't have enough resources on your computer to run both the Docker desktop VM and the minikube VM at the same time and will eventually slow down your computer.

为了解决 docker-desktop UI for Mac and Windows 提供了一个比 minikube 更简单的替代方案,你可以简单地 activate the Kubernetes feature on your docker-desktop UI:

设置完成后,您可以右键单击 docker 桌面图标 > Kubernetes

现在验证您的 deployement/service 是否正常工作:

kubectl apply -f /file.yaml

如果您在 Windows 中 运行ning minikube,则 minikube 必须 运行 作为管理员命令提示符 window。