<p>My k8 cluster runs on minikube.</p>
<p>I am familiar with kubectl port-forward command which allows to route traffic from localhost into the cluster.</p>
<p>Is there a way do do it the other way around? Can I route the traffic from one of the pods to the web server that runs locally on my machine?</p>

Pavel Ryvintsev
<p>The way to connect from your <code>minikube</code> pod to your host will heavily depend on the type of <code>--driver</code> you used.</p>
<p>Each <code>--driver</code> could alter the way to connect from your pod to your host. What I mean is that there could be multiple options for each <code>--driver</code> to connect to your host.</p>
<p>As pointed by user @Srikrishna B H</p>
<blockquote>
<p>Make sure you use local machine IP instead of <code>localhost</code> while connecting to web server running locally in your machine.</p>
</blockquote>
<p>I've created 3 examples:</p>
<ul>
<li>Ubuntu with <code>minikube start --driver=docker</code></li>
<li>Mac OS with <code>minikube start --driver=hyperkit</code></li>
<li>Windows with <code>minikube start --driver=virtualbox</code></li>
</ul>
<blockquote>
<p><strong>IP addresses used below are only for example purposes!</strong></p>
</blockquote>
<hr />
<h3>Ubuntu with Docker</h3>
<p>Assuming that you have an Ubuntu machine with Docker installed and <code>nginx</code> working as a server that your pod will connect to:</p>
<ul>
<li><code>$ minikube start --driver=docker</code></li>
<li><code>$ ip addr show</code>:
<ul>
<li><code>docker0</code> - docker interface</li>
<li><code>ensX</code> - &quot;physical&quot; interface</li>
</ul>
</li>
</ul>
<p>Above command will tell you the IP address to connect from your pod (on host)</p>
<pre class="lang-sh prettyprint-override"><code>2: ensX: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1460 qdisc mq state UP group default qlen 1000
    &lt;----&gt; 
    inet 10.0.0.2/32 scope global dynamic ensX 
    &lt;----&gt; 
</code></pre>
<pre class="lang-sh prettyprint-override"><code>3: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default 
    &lt;----&gt;
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
    &lt;----&gt;
</code></pre>
<p>Then you can spawn a pod to check if you can connect to your nginx:</p>
<ul>
<li><code>$ kubectl run -i --tty busybox --image=busybox --restart=Never -- sh</code></li>
<li><code>$ wget -q0 - IP_ADDRESS</code> - <code>busybox</code> image doesn't have <code>curl</code> installed
<ul>
<li><code>172.17.0.1</code></li>
<li><code>10.0.0.2</code></li>
</ul>
</li>
</ul>
<hr />
<h3>Mac OS with Hyperkit</h3>
<p>Assuming that you have a Mac OS machine and you have configured <code>nginx</code> on port <code>8080</code>:</p>
<ul>
<li><code>$ minikube start --driver=hyperkit</code></li>
<li><code>$ ifconfig</code>:
<ul>
<li><code>bridge100</code></li>
<li><code>enX</code> - &quot;physical&quot; interface</li>
</ul>
</li>
</ul>
<blockquote>
<p>Disclaimer!</p>
<p>You will need to allow connections to your nginx outside of <code>localhost</code> in the firewall or completely disable it (not recommended!)</p>
</blockquote>
<pre class="lang-sh prettyprint-override"><code>bridge100: flags=8a63&lt;UP,BROADCAST,SMART,RUNNING,ALLMULTI,SIMPLEX,MULTICAST&gt; mtu 1500
    &lt;----&gt;
    inet 192.168.64.1 netmask 0xffffff00 broadcast 192.168.64.255
    &lt;----&gt;
</code></pre>
<pre class="lang-sh prettyprint-override"><code>enX: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
    &lt;----&gt; 
    inet 192.168.1.101 netmask 0xffffff00 broadcast 192.168.0.255 
    &lt;----&gt;
</code></pre>
<p>Then you can spawn a pod to check if you can connect to your nginx:</p>
<ul>
<li><code>$ kubectl run -i --tty busybox --image=busybox --restart=Never -- sh</code></li>
<li><code>$ wget -q0 - IP_ADDRESS</code> - <code>busybox</code> image doesn't have <code>curl</code> installed
<ul>
<li><code>192.168.64.1:8080</code></li>
<li><code>192.168.1.101:8080</code></li>
</ul>
</li>
</ul>
<hr />
<h3>Windows with Virtualbox</h3>
<p>When you create a <code>minikube</code> instance with <code>--driver=virtualbox</code> in Windows, it creates a <code>VM</code> with 2 network interfaces:</p>
<ul>
<li><code>NAT</code> - used to communicate with outside (Internet)</li>
<li><code>Virtualbox Host-Only Ethernet Adapter</code> - used to communicate between <code>minikube</code> and your host</li>
</ul>
<p>Assuming that you have a Windows machine with Virtualbox, you have configured <code>nginx</code> on port <code>80</code> and also you have a running <code>minikube</code> instance.</p>
<p>You will need to get the IP addresses of (<code>$ ipconfig</code>) :</p>
<ul>
<li>Your &quot;physical&quot; interface (<code>Ethernet X</code> for example)</li>
<li>Your <code>Virtualbox Host-Only Ethernet Adapter</code></li>
</ul>
<pre class="lang-bsh prettyprint-override"><code>Ethernet adapter Ethernet X:
   &lt;----&gt; 
   IPv4 Address. . . . . . . . . . . : 192.168.1.3 
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1
</code></pre>
<pre class="lang-bsh prettyprint-override"><code>Ethernet adapter VirtualBox Host-Only Network #X:
   &lt;---&gt; 
   IPv4 Address. . . . . . . . . . . : 192.168.99.1 
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
</code></pre>
<blockquote>
<p>Disclaimer!</p>
<p>You will need check if your firewall will accept the traffic destined for ngin (If it's not blocked).</p>
</blockquote>
<p>Then you can spawn a pod to check if you can connect to your nginx:</p>
<ul>
<li><code>$ kubectl run -i --tty busybox --image=busybox --restart=Never -- sh</code></li>
<li><code>$ wget -q0 - IP_ADDRESS</code> - <code>busybox</code> image doesn't have <code>curl</code> installed
<ul>
<li><code>192.168.99.1</code></li>
<li><code>192.168.1.3</code></li>
</ul>
</li>
</ul>
