Expose Kubernetes services with ngrok

Very often, there is a need to expose Kubernetes apps running in minikube to the public internet. This post just provides a manual, yet quick and dirty hack for this using ngrok (it’s probably been done before, but here it goes anyway)

We’ll use a simple nginx app to test things out i.e. we’ll expose an nginx server (running as a single replica Kubernetes Deployment) as a publicly accessible URL.

Test app (nginx)

Start by creating the nginx Deployment

Expose it inside the cluster by creating a corresponding Service (typeClusterIP)

Enter ngrok..

To expose the nginx Service we just created, we can create a ngrok deployment which will run the ngrok process with an HTTP tunnel to the nginx Service(using the Service name)

Create the ngrok Deployment

Now you need to extract the ngrok URL. The below command does a couple of things

  • gets the Pod for the ngrok Deployment
  • uses the HTTP endpoint inside of the ngrok Pod to get the details (using kubectl exec inside the running Pod)

Output will be similar to what you see below — refer to the public_url field to grab the ngrok URL accessible via public internet (in this example, it’s https://b42658ec.ngrok.io)

Access the URL and it should lead you to ngnix home page

nginx in k8s exposed via ngrok


…. if you want to access the ngrok dashboard

Expose it using aService (type NodePort)

Check the random port

Get the Minikube IP

Open it in your browser

You should see the dashboard

ngrok dashboard

That’s all there is to it. The code (just a bunch of YAMLs) is on GitHub


Azure Cosmos DB at Microsoft | I like Databases, Go, Kubernetes

Love podcasts or audiobooks? Learn on the go with our new app.