Getting Started with minikube
What’s up guys, this is Daniel! Yeah, this English blog is WRITTEN by me, not TRANSLATED by me! It’s my first English blog in my whole life. If you are a Chinese reader, maybe you’ve ever seen my Chinese blogs before. Right, I wrote a lot of blogs, but only in Chinese. Believe it or not, English isn’t my strong suit. But I want to have a try today and I’ll do my best. Let’s get started.
What We Will Talk about Today
If you ask me how to create a local Kubernetes cluster, I’ll tell you Kind, minikube, and Kubeadm are all good choices. If you ask me which tool is the most recommended for beginners, my answer must be
minikube is more powerful than
Kind is easier than
In my previous article, I walked you guys through “How to Create a Local Kubernetes Cluster from the Ground Up” with
Kind. If you are interested, here’s a quick link for you:
You might ask why that article is written by Tiexin Guo, not me. Of course! As I said in the beginning, this blog you are reading now is my first English blog. So, technically, the one above isn’t “my” article, but I did write the Chinese version of it:
Kind are the most well-known and popular choices to run a Kubernetes environment on a local computer. Since I’ve shown you how to use
Kind, I might as well introduce
minikube to youadorable today.
Quick Start with
minikube is a command-line tool like
Kind that you can use to create and configure Kubernetes clusters locally on your computer.
How to Install
If your computer is the same as mine, Mac with m1 chip, you can install the latest
minikube stable release in 2 steps:
If you are using
Homebrew, just one command:
If your computer is of other platforms or architectures, see the “Installation” section in minikube start for more details.
Like the section title we used here, to start using minikube, run
Ok, it doesn’t matter; we need to install Docker. In my previous article How to Create a Local Kubernetes Cluster from the Ground Up, I introduced how to “Install Docker”.
After the Docker is installed, what we’ll need in total?
- A not too bad computer;
- Internet connections;
- Container or virtual machine hypervisor, such as: Docker, Hyper-V, KVM, VirtualBox, or VMware Workstation …
Let’s try to run
minikube start again. This command is time-consuming the first time you use it, especially if the network speed is low. Feel free to have a cup of coffee then come back to see the result.
2000 years later…
Well Done! 0 error, 0 warning! The logs are beautiful!
Access Your Shiny Kubernetes Cluster
Do you have
kubectl installed? If yes, you can now use it to access your shiny Kubernetes cluster:
minikube can download the appropriate version of
kubectl with the command
Are you thinking this command is too complicated? Use the config below and you’ll be happy:
I’m used to command-line to access the Kubernetes cluster. Yes, I never use the Kubernetes Dashboard. But if you like to have some insight into your cluster state with a Dashboard,
minikube bundles it for you:
At this time, your browser will automatically open a new tab, and the Dashboard will soon show up:
Deploy an Application in Your Shiny Kubernetes Cluster
Let’s create a sample deployment with the image
preslavmihaylov/kubehelloworld:latest and expose it on port 3000.
The minikube start told us to use the
k8s.gcr.io/echoserver:1.4 to launch the
hello-minikube application, but it’ll fail on a Mac with m1 chip. See this issue for more details.
Then we can use
kubectl to forward the port:
Open the browser, visit
localhost:3000, and “Hello World!” will soon show up.
Another way to access this service is to use the
minikube service sample-deploy command and minikube will launch a browser page for you with the right
And we can use the command
minikube tunnel to use the
LoadBalancer type Service. Here is an example:
In another terminal window, start the tunnel to create a routable IP with the command
Now you can use the
EXTERNAL-IP to access the Service:
How to Manage the Cluster
I’ll show you some commands here:
minikube pause# Pause Kubernetes cluster without impacting any deployed resources.
minikube unpause# Unpause the Paused Kubernetes cluster.
minikube stop# Remember the
minikube start? Need I say more?
minikube config set memory 20480# Change the default memory limit (requires a restart).
minikube addons list# Browse the easily installed Kubernetes addons catalog.
minikube start -p aged --kubernetes-version=v1.16.1# Create a second cluster running an older Kubernetes version.
minikube delete --all# Yeah, delete all, delete anything, delete all clusters.
No! But if you want to know them all, I’ll show you the command docs here.
How to Push Images into a
There are about 8 ways you can use to push images into a
minikube cluster. And I’ll show you the most useful two ways today.
Push Images with the
minikube cache add [flags] [options]# Add an image to local cache.
Cache? Yes, the image will be cached by minikube and automatically pushed into all clusters, not like the
kind load docker-image <IMAGE> [IMAGE...] [flags].
Let’s see how many sub-commands
Easy, isn’t it?
The only sub-command we need to talk about might be
reload. If your image changed after you had cached it, you need to execute
minikube cache reload [flags] [options]
minikube cache add alpine:latest# Cache alpine:latest for all clusters.
minikube cache reload alpine:latest# Reload alpine:latest if it’s changed.
minikube cache list# Display what images we have added to the cache.
minikube cache delete alpine:latest# Just delete alpine:latest
Pushing Directly to the In-Cluster Docker Daemon
If the image we want to use inside the
minikube cluster is built locally instead of pulled from a registry, we can reuse the Docker daemon inside the
minikube cluster. Yeah, we don’t have to build the image on our host machine and
cache it; we can just build inside the same docker daemon inside the
After the command
eval $(minikube docker-env) is executed,
docker accesses the docker daemon inside the
minikube cluster! What’s the secret with
minikube docker-env command? Let’s dig into it:
I don’t think I need to explain more about what happened. And we can
build against the Docker inside
minikube now. Just execute a command like
docker build -t my-image:latest .,
my-image:latest is instantly accessible to the Kubernetes cluster.
How to …
Oops, there are many how-tos we could talk about, but I believe that you can start using
minikube now. Maybe I’ll talk about more how-tos next time. If you want to dive into
minikube now, go ahead and study the official documentation.
Cool, I finished writing this blog, It’s like opening Pandora’s box; I love this feeling. Of course, I know this blog is at the primary-school-student level, but I believe I can do better and better.
Don’t forget to give a Like, Comment, and Subscribe! I’ll see you in the next article!