Running Kubernetes Locally Using Minikube and Ngrok

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 test k8s integrations.

Why do we need local Kubernetes?

Before we start into how to get Kubernetes running in your local environment, we should first go over a few reasons why you might want to do that in the first place.

Running Kubernetes locally allows you to:

  • Develop and test Kubernetes manifests on an ephemeral cluster
  • Install and test addons like different ingress controllers
  • Try external tools (like ShuttleOps) without adding a real cluster

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

Suitable K8s Distributions

There are several projects that allow for running a Kubernetes cluster locally. This tutorial will initially focus on using minikube which is an official Kubernetes project and easy to get up and running.

Two other interesting options are:

  • k3s – a lightweight, production ready distribution focusing on the Edge and IOT
  • k0s – a “batteries included” distribution that packages all required k8s components in a single binary

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 are should use curl to download the binary.

Start the cluster

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

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

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

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. We will demonstrate this by connecting your local cluster to ShuttleOps.

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

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

Deploy to your development cluster

Firstly, you will need to create a ShuttleOps account for free before we can connect the cluster.

Create a ShuttleOps service account

These commands will output a token.txt file with your token inside:

This command will output a cluster-config.txt file that contains the cluster CA certificate:

The CA certificate will be shown as certificate-authority-data.

Set up the connection

To add a Kubernetes connection navigate to the connect page and add a new Kubernetes connection.

The form data should be filled out using these values:

Get Deploying

Once you’ve saved the connection, head over to the deploy section and start creating deployment pipelines!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Why We Lowered Our Pricing

Would it be cliché to say that the world is rapidly changing? I would tend to say yes; however,...
Continue reading

Machines Have Identities Too!

Consider this – every network has 2 types of users: humans and machines. While human users identify themselves using...
Continue reading
Docker and Kubernetes

How Docker & Kubernetes Help Provide a...

This blog post is for the person interested in Kubernetes and Docker but hasn’t fully taken the leap, or...
Continue reading