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
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
virtualboxas it is a well supported minikube driver on Mac, Linux, and Windows.
- ngrok – Used for exposing the kubernetes API to the internet
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
--driver=virtualbox flag to tell minikube the driver it should use:
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
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:
Once you’ve saved the connection, head over to the deploy section and start creating deployment pipelines!