简体   繁体   English

各种 Minikube + Kubernetes IP 地址有什么区别?

[英]What's the difference between various Minikube + Kubernetes IP addresses?

I'm trying to make sense of Kubernetes so I can start using it for local development, but I'm stumbling over some basics here...我正在尝试了解 Kubernetes,以便我可以开始将它用于本地开发,但我在这里遇到了一些基础知识......

I'm running on Mac OS X and I've installed Kubernetes using Homebrew via brew install kubernetes .我在 Mac OS X 上运行,我已经通过brew install kubernetes使用 Homebrew brew install kubernetes After this, I started up a simple app (deployment? service? -- I'm not clear on the terminology) like so:在此之后,我启动了一个简单的应用程序(部署?服务? - 我不清楚术语),如下所示:

$> minikube start
$> kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
$> kubectl expose deployment hello-minikube --type=NodePort --port=8080

I got these commands directly fromthe Kubernetes documentation我直接从Kubernetes 文档中得到了这些命令

Now each step of the way I've been trying to read through the Kubernetes docs and experiment a bit with the various command line tools so that I'm not just blindly following, but actually understanding what's going on.现在,我一直在尝试通读 Kubernetes 文档并尝试使用各种命令行工具进行一些实验,这样我就不会只是盲目地遵循,而是真正了解正在发生的事情。 And this is where I ran into my first huge hurdle: there are too many IP addresses!这就是我遇到第一个巨大障碍的地方: IP 地址太多了!

$> ifconfig
...
        inet 192.168.2.126 netmask 0xffffff00 broadcast 192.168.2.255
...
$> minikube ip
192.168.64.3
$> kubectl describe pods
...
IP:          172.17.0.2
...
$> kubectl describe services
...
IP:                    10.96.8.59
...

I understand a couple of these:我理解其中的几个:

  • 192.168.2.126 is my local machine's IP address on the network, and it's how another computer on the network would access my computer (if, for instance, I were running nginx or something) 192.168.2.126 是我本地机器在网络上的 IP 地址,它是网络上的另一台计算机访问我的计算机的方式(例如,如果我正在运行 nginx 或其他东西)
  • 192.168.64.3 is the IP address assigned to the virtual machine that Minikube is running. 192.168.64.3 是分配给 Minikube 运行的虚拟机的 IP 地址。 I know that my computer should be able to access this IP directly, but I don't know how to expose this IP address to other computers on the network我知道我的电脑应该可以直接访问这个IP,但是我不知道怎么把这个IP地址暴露给网络上的其他电脑

But I have no idea what's up with 172.17.0.2 and 10.96.8.59 -- what are these IP addresses, when would I need to use them, and how do I access them?但我不知道172.17.0.2 和 10.96.8.59 是怎么回事——这些 IP 地址是什么,我什么时候需要使用它们,以及如何访问它们?

One more thing还有件事

When I try accessing xxx.xxx.xxx.xxx:8080 for any of the four IP addresses in my browser, the echoserver application that I'm running does not come up.当我尝试为浏览器中的四个 IP 地址中的任何一个访问xxx.xxx.xxx.xxx:8080 ,我正在运行的 echoserver 应用程序没有出现。 The host simply times out.主机只是超时。 However using minikube service hello-minikube --url (perthe docs ) I get: http://192.168.64.3:30866但是使用minikube service hello-minikube --url (根据文档)我得到: http : //192.168.64.3 : minikube service hello-minikube --url

I can understand why I'm getting Minikube's IP address (how else would my computer access a container running inside the VM, except to connect to the VM directly and have the VM port forward?) -- but I don't understand:我能理解为什么我得到Minikube的IP地址(怎么回事就在我的电脑访问虚拟机内运行的容器,除了直接连接到虚拟机,并在VM端口转发?) -但我不明白:

  • Where port 30866 came from 30866 端口来自哪里
  • How Minikube is aware of the hello-minikube service, since it was created using kubectl and not minikube Minikube 如何知道 hello-minikube 服务,因为它是使用 kubectl 而不是 minikube 创建的

Also slightly related: I don't know how kubectl knew to connect to the Minikube VM and send commands to the Kubernetes API server on that cluster.也略有涉及:我不知道kubectl怎么知道连接到Minikube VM和发送命令群集上的Kubernetes API服务器。 I never told kubectl that I had a VM running, nor did I tell it how to connect to that VM.我从来没有告诉 kubectl 我有一个虚拟机在运行,也没有告诉它如何连接到那个虚拟机。 But somehow it just knew .但不知何故它只是知道

I know this is like three different questions (what each of the IP addresses mean, how Minikube is port forwarding, and how kubectl is communicating with Minikube) - but these are all questions that arose from following the first step of Minikube's tutorial, and I can't seem to find answers on my own.我知道这就像三个不同的问题(每个 IP 地址的含义,Minikube 如何进行端口转发,以及 kubectl 如何与 Minikube 通信)——但这些都是从 Minikube 教程的第一步中产生的问题,我似乎无法自己找到答案。

ifconfig is really helpful in understanding how the origin of each IP address that we are looking at. ifconfig 非常有助于理解我们正在查看的每个 IP 地址的来源。 Each of the IPs are coming from various subnets.每个 IP 都来自不同的子网。

192.168.64.3 is the internal IP address which comes from interface of our virtual machine's network. 192.168.64.3是来自我们虚拟机网络接口的内部 IP 地址。

172.17.0.2 is the internal IP address which comes from the docker's network interface. 172.17.0.2是来自 docker 网络接口的内部 IP 地址。 This allows network isolation from host and the container that we run.这允许与主机和我们运行的容器进行网络隔离。

10.96.8.59 is the internal IP address which comes from the Virtual Machines own network interface. 10.96.8.59是来自虚拟机自身网络接口的内部 IP 地址。 This you can confirm by ssh-ing into the VM ( minikube ssh ) and running the command ifconfig over there.您可以通过 ssh 进入 VM ( minikube ssh ) 并在那里运行命令 ifconfig 来确认。 This allocation can be controlled by the option --service-cluster-ip-range when we run the minikube start当我们运行 minikube start 时,这个分配可以通过选项--service-cluster-ip-range来控制

what's up with 172.17.0.2 and 10.96.8.59 -- what are these IP addresses, when would I need to use them, and how do I access them? 172.17.0.2 和 10.96.8.59 怎么了——这些 IP 地址是什么,我什么时候需要使用它们,以及如何访问它们?

IP address 10.96.8.59 can be access only through another VM. IP 地址10.96.8.59只能通过另一个 VM 访问。 For example if you attach more VMs to your existing minikube cluster then you can access the 10.96.8.59 through the other VM.例如,如果您将更多 VM 附加到现有的 minikube 集群,那么您可以通过另一个 VM 访问10.96.8.59 Also IPs in the range of 10.96.xx.xx will be used in intra-pod communication. 10.96.xx.xx 范围内的 IP 也将用于 pod 内通信。 whereas the 172.17.0.2 will be used in inter pod communication.172.17.0.2将用于 Pod 间通信。

Where port 30866 came from? 30866端口从哪里来?

That's a random choice from a range of ports made by the minikube in order to expose your service to your network.这是从 minikube 制作的一系列端口中随机选择的,以便将您的服务暴露给您的网络。 By Default the range of ports to which minikube exposes our services is 30000-32767 But if you want to manipulate that, please refer this doc默认情况下,minikube 暴露我们服务的端口范围是30000-32767但是如果你想操作它,请参考这个文档

how kubectl knew to connect to the Minikube VM kubectl 如何知道连接到 Minikube VM

If you do minikube start we see that minikube tries to setup the VM and then configure kubectl to get attached to the VM.如果您执行 minikube start,我们会看到 minikube 尝试设置 VM,然后配置 kubectl 以连接到 VM。 For this kubectl to know which host to connect to;为了让这个 kubectl 知道要连接到哪个主机; all these informations are stored in the config file found at ~/.kube/ here you will find the server IP:port combination.所有这些信息都存储在~/.kube/中的配置文件中,您将在这里找到服务器 IP:port 组合。

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

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