<p>I installed minikube in the Azure cloud on an ubuntu machine 18.04. But I do not know how to connect to it through kubectl using real IP of the virtual machine. Using i minikube on virtualbox driver (<a href="https://192.168.99.100:8443" rel="nofollow noreferrer">https://192.168.99.100:8443</a>). Please tell me how to make port forwarding? Thanks. </p>

Vitalii Fedorenko
<p>I tested it and come up with some solutions.</p>

<ol>
<li><p>The easiest way to make minikube accessible from your local machine can be achieved by using ssh port forwarding (but you need to remember to have ssh session open all the time and its not really what you want because it will be accessible only from your local machine).</p>

<p>You can run:</p>

<pre><code>ssh &lt;user&gt;@&lt;azure_vm_ip&gt; -L 8443:192.168.99.100:8443
</code></pre>

<p>to start port forwarding from your local host to the minikube vm.</p>

<p>You will also need to copy these certificate files from azure vm <code>~/.minikube/</code> directory to 
you local machine:</p>

<pre><code>ca.crt
client.crt
client.key
</code></pre>

<p>also copy <code>.kube/config</code> from azure vm to you local machine and edit paths to certificate files mentioned earlier and change server IP address to localhost.</p></li>
<li><p>second way to make it accessible (this time allowing for external access) using ssh port forwarding is possible by doing the following:</p>

<p>In file <code>/etc/ssh/sshd_config</code> on azure vm change <code>GatewayPorts</code> to <code>yes</code>, save file and run</p>

<pre><code>systemctl restart sshd
</code></pre>

<p>next, ssh to your azure vm and run:</p>

<pre><code>ssh -R 0.0.0.0:8443:192.168.99.100:8443 localhost
</code></pre>

<p>remember about certificate files and change server IP in <code>.kube/config</code> file  public IP of your azure vm.</p>

<p>When trying to connect to minikube form you local machine may see:</p>

<pre><code>$ kubectl get pods
Unable to connect to the server: x509: certificate is valid for 192.168.99.100, 10.96.0.1, 10.0.0.1, not &lt;your_vm_ip&gt;
</code></pre>

<p>So you need to either use <code>--insecure-skip-tls-verify</code> flag or generate new valid certificates (or start minikube with <code>--apiserver-ips=&lt;public_ip&gt;</code> and it will generate valid certificate for you).</p>

<p>NOTE: remember to allow ingress traffic to your azure vm on port 8443.</p>

<p>If you don't want to use ssh port forwarding you can use any kind of proxy e.g nginx, that will run on azure vm and forward requests to minkube vm</p></li>
<li><p>Probably the best way. Running without a VM:</p>

<pre><code> sudo minikube start --vm-driver=none --apiserver-ips=&lt;public_ip&gt;
</code></pre>

<p><code>--apiserver-ips</code> is needed to generate appropriate certificates.
<code>--vm-driver=none</code> won't create a vbox vm</p>

<p>Now all you need is to copy certificates to your local machine and provide appropriate server ip in <code>.kube/confg</code> file.</p></li>
</ol>

<p>Let me know if it was helpful.</p>
