Skip to content

Running Kubernetes Locally Using Minikube and Ngrok

May 16, 2024

Greg Schofield

This tutorial will go through the steps to create a Kubernetes developer sandbox using minikube. We will also show you how to expose a minikube cluster using ngrok so you can access your Kubernetes cluster from the internet. 

Why might we want to expose minikube to the internet? 

Before we start into how to get minikube setup with an ngrok tunnel, we should first go over a few reasons why you might want to do that in the first place. 

Running minikube with a ngrok tunnel allows you to: 

  • Test out some cloud-based SaaS platforms like WeaveWorks, OctopusDeploy, etc. without using a cloud-based Kubernetes cluster. 
  • Perform PoCs with different ingress controllers. 
  • Develop and test Kubernetes manifests on an ephemeral cluster. 

Think of it as a development sandbox environment that you can setup for free on your own computer! 

Prerequisites 

To follow along with this tutorial your computer should have at least: 

  • 2 CPUs or more 
  • 4GB of free memory 
  • 20GB of free disk space 
  • kubectl - the Kubernetes CLI 
  • virtualbox - We recommend virtualbox as it is a well-supported minikube driver on Mac, Linux, and Windows. 
  • ngrok - Used for exposing the kubernetes API to the internet 

Install Minikube 

Installing minikube is easy since it is a standalone binary. Mac and Windows both have official installs available from a package manager. Linux distros should use curl to download the binary. 

<script src="https://gist.github.com/ShivKamal/61fb436b8452cc18c3f882c45158c438.js"></script> 

Start the cluster 

Pass the --driver=virtualbox flag to tell minikube the driver it should use: 

<script src="https://gist.github.com/ShivKamal/fb5a09d8a7dae59b75ccfdc7c4fa1e3f.js"></script> 

The config set driver command will allow you to set the default so you can omit the flag next time: 

<script src="https://gist.github.com/ShivKamal/68cd0a0ca4cae37bbb4c11f0969f8b26.js"></script> 

At this point you should use minikube status and make sure the output looks like this: 

<script src="https://gist.github.com/ShivKamal/5507c04e9b268efcffa44d9af289fd6b.js"></script> 

Exposing the Kubernetes API to the internet 

Now that our cluster is running locally, we can use ngrok to make it accessible to the internet. By making it accessible to the internet, you can test integrating with CI tools or try a SaaS platform for free. 

The first thing we need to do is use kube-proxy to proxy requests to the API from localhost: 

<script src="https://gist.github.com/ShivKamal/3dc339a61570ed66427f2a589f0c694d.js"></script> 

Next we can open an ngrok tunnel (port 8001 is the default Kubernetes API port): 

<script src="https://gist.github.com/ShivKamal/47ae826ce13f4c58b66a8df60aa08b2e.js"></script> 

The ngrok UI will output an HTTPS address that points directly to your minikube's API port. You can now use that URL to run kubectl commands against. 

Got a Project?