简体   繁体   中英

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...

I'm running on Mac OS X and I've installed Kubernetes using Homebrew via 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

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. And this is where I ran into my first huge hurdle: there are too many IP addresses!

$> 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.64.3 is the IP address assigned to the virtual machine that Minikube is running. 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

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?

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. The host simply times out. However using minikube service hello-minikube --url (perthe docs ) I get: http://192.168.64.3:30866

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:

  • Where port 30866 came from
  • How Minikube is aware of the hello-minikube service, since it was created using kubectl and not 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. I never told kubectl that I had a VM running, nor did I tell it how to connect to that VM. 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.

ifconfig is really helpful in understanding how the origin of each IP address that we are looking at. Each of the IPs are coming from various subnets.

192.168.64.3 is the internal IP address which comes from interface of our virtual machine's network.

172.17.0.2 is the internal IP address which comes from the docker's network interface. 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. This you can confirm by ssh-ing into the VM ( minikube ssh ) and running the command ifconfig over there. This allocation can be controlled by the option --service-cluster-ip-range when we run the minikube start

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?

IP address 10.96.8.59 can be access only through another 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. Also IPs in the range of 10.96.xx.xx will be used in intra-pod communication. whereas the 172.17.0.2 will be used in inter pod communication.

Where port 30866 came from?

That's a random choice from a range of ports made by the minikube in order to expose your service to your network. 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

how kubectl knew to connect to the 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. For this kubectl to know which host to connect to; all these informations are stored in the config file found at ~/.kube/ here you will find the server IP:port combination.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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