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

<p>I'm running on Mac OS X and I've installed Kubernetes using Homebrew via <code>brew install kubernetes</code>. After this, I started up a simple app (deployment? service? -- I'm not clear on the terminology) like so:</p>

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

<p>I got these commands directly from <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/" rel="nofollow noreferrer">the Kubernetes documentation</a></p>

<p>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 <strong><em>too many IP addresses!</em></strong></p>

<pre><code>$&gt; ifconfig
...
        inet 192.168.2.126 netmask 0xffffff00 broadcast 192.168.2.255
...
$&gt; minikube ip
192.168.64.3
$&gt; kubectl describe pods
...
IP:          172.17.0.2
...
$&gt; kubectl describe services
...
IP:                    10.96.8.59
...
</code></pre>

<p>I understand a couple of these:</p>

<ul>
<li>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)</li>
<li>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</li>
</ul>

<p>But I have <strong><em>no idea</em></strong> 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?</p>

<h2>One <em>more</em> thing</h2>

<p>When I try accessing <code>xxx.xxx.xxx.xxx:8080</code> for <strong><em>any</em></strong> 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 <code>minikube service hello-minikube --url</code> (per <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/" rel="nofollow noreferrer">the docs</a>) I get: <a href="http://192.168.64.3:30866" rel="nofollow noreferrer">http://192.168.64.3:30866</a></p>

<p>I can understand why I'm getting Minikube's IP address (how <strong>else</strong> 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:</p>

<ul>
<li>Where port 30866 came from</li>
<li>How Minikube is aware of the hello-minikube service, since it was created using kubectl and not minikube</li>
</ul>

<p>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 <strong><em>that</em></strong> 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 <em>just knew</em>.</p>

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

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

<p><code>192.168.64.3</code> is the internal IP address which comes from interface of our virtual machine's network. </p>

<p><code>172.17.0.2</code> 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.</p>

<p><code>10.96.8.59</code> is the internal IP address which comes from the Virtual Machines own network interface. This you can confirm by ssh-ing into the VM (<code>minikube ssh</code>) and running the command ifconfig over there. This allocation can be controlled by the option <code>--service-cluster-ip-range</code> when we run the minikube start</p>

<blockquote>
  <p>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?</p>
</blockquote>

<p>IP address <code>10.96.8.59</code> can be access only through another VM. For example if you attach more VMs to your existing minikube cluster then you can access the <code>10.96.8.59</code> through the other VM. Also IPs in the range of 10.96.xx.xx will be used in intra-pod communication. whereas the <code>172.17.0.2</code> will be used in inter pod communication. </p>

<blockquote>
  <p>Where port 30866 came from?</p>
</blockquote>

<p>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 <code>30000-32767</code>
But if you want to manipulate that, please refer this <a href="https://github.com/kubernetes/minikube/blob/master/site/content/en/docs/Tasks/nodeport.md#increasing-the-nodeport-range" rel="noreferrer">doc</a></p>

<blockquote>
  <p>how kubectl knew to connect to the Minikube VM</p>
</blockquote>

<p>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 <code>~/.kube/</code> here you will find the server IP:port combination.</p>
