In this Kubernetes Minikube tutorial, I will go through the required steps for a beginner to get started with Minikube.
Minikube is an open-source tool that helps you create a local Kubernetes cluster for learning and development.
In this Minikube beginner tutorial, we will look at the following.
Table of Contents
- Minikube Prerequisites
- Installing MiniKube
- Start Minikube With Virtualbox/Qemu/Docker
- Minikube Reference Manifests
- Deploy Application on Minikube
- Getting Minikube IP & Service Endpoints
- Access Nodeport on Minikube
- Create Persistent Volume on Minikube
- Create Dynamic Volumes on Minikube
- Minikube Addons
- Access Minikube Kubernetes Dashboard
- Minikube Custom CPU & Memory
- Running Multiple Minikube Clusters using Profiles
- Running Multi-Node Minikube Cluster
- Access Minikube Nodes (SSH)
- Minikube Alternatives
- Minikube FAQs
The following are the prerequisites for Minikube to work properly.
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- A good Internet connection
- Container or virtual machine manager, such as: Docker, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMWare. Ensure you install any of the tools before you start with Minikube installation.
Note: I recomend installing Virtualbox as the backend minikube driver. It works without any issues.
MAC M1/M2 users can use qemu emulator as virtual box have issue with ARM64 processors.
Minikube installation is very simple. You just need to download the package. It is a single binary that is executable and that is all you need.
First, go to https://minikube.sigs.k8s.io/docs/start/ and select the appropriate OS and other OS-specific parameters. You will get the installation commands for the specific OS as shown below.
For example, if you have selected MAC binary download, the installation of Minikube is as simple as,
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 sudo install minikube-darwin-amd64 /usr/local/bin/minikube
Verify installation by checking the minikube version.
Start Minikube With Virtualbox/Qemu/Docker
I personally prefer Virtualbox because I use it for other testing purposes using Vagrant.
If you use the Docker driver, Nodeport will not work properly.
You can install Virtualbox and start minikube with the Virtualbox driver. There will not be any issue with NodePort services if you use the Virtualbox driver.
minikube start --driver=virtualbox
For Docker users,
minikube start -p dev --container-runtime=docker --vm=true
For Qemu users.
minikube start --driver=qemu
Here we are specifically mentioning –driver=virtualbox because, by default, it picks the Docker driver if Docker is installed on your system. If you don’t have Docker and only Virtualbox, minikube picks the Virtualbox driver by default.
If you want to install a specific kubernetes version, use the version flag as shown below.
minikube start --kubernetes-version=1.24.10 --driver=virtualbox
If you are running for the first time, Minikube will download the base VM image to deploy kubernetes on Virtualbox. It will take a couple of minutes for minikube to start. On successful execution, you will see the following messages.
To verify, execute the following status command.
You should see the following output.
minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured
You can have multiple minikube clusters using profiles. I have covered profiles towards the end of the article.
Minikube Reference Manifests
All the Kubernetes manifests used in this guide are hosted on Github. You can clone the repo and use it or directly deploy it using the URL as given in the guide below.
git clone https://github.com/scriptcamp/minikube.git
Deploy Application on Minikube
First, let’s deploy a sample Nginx app. Here is what that manifest contains.
- A configmap with custom nginx html
- Nginx deployment
- Service with 32000 nodeport
Note: Please ensure you have kubectl installed. If not, follow the Kubectl installtion guide
Let’s deploy the manifest using the direct git raw URL. It gets deployed in the default namespace.
kubectl apply -f https://raw.githubusercontent.com/scriptcamp/minikube/main/nginx.yaml
Get the deployment status
kubectl get deployments
Get the service. You should be able to see the
kubectl get service
Getting Minikube IP & Service Endpoints
To get the node IP of minikube, execute the following command. You can use the IP to access nodePorts.
You can also get the service endpoint directly using the following minikube command.
minikube service list
To get the URL of a specific service,
minikube service --url <service-name>
Access Nodeport on Minikube
With minikube, you can get the service endpoint with the NodePort directly using the service name. Execute the following command to get the full service url with assigned
nginx-service is the service name of nginx.
minikube service nginx-service --url
Create Persistent Volume on Minikube
You can create Persistent volume in your minikube cluster. If any of the applications need persistent volume, you can use the host path type.
Here is an example.
apiVersion: v1 kind: PersistentVolume metadata: name: pv0001 spec: accessModes: - ReadWriteOnce capacity: storage: 5Gi hostPath: path: /data/pv0001/
You can try creating a persistent volume using the GitHub manifest directly.
kubectl apply -f https://github.com/scriptcamp/minikube/edit/main/pv.yaml
kubectl get pv
Create Dynamic Volumes on Minikube
When you install Minikube, a default storage class named standard is created for dynamic provisioning. Dynamic volume provisioning is primarily required when you deploy statefulset apps.
Minikube uses provisioner:k8s.io/minikube-hostpath provisioner for the dynamic persistent volume. Which is actually creates a mount under the hostpath.
Here is a PVC manifest example that you can use with minikube.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: dynamic-volume spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
Let’s try creating the PVC using the manifest directly from the Github file.
kubectl apply -f https://raw.githubusercontent.com/scriptcamp/minikube/main/pvc.yaml
List the pvc
kubectl get pvc
You can check the kubernetes postgreSQL statefulset guide to deploy Statefulsets on Minikube.
There are some advanced Kubernetes features that are available as minikube addons. For example, the Kubernetes dashboard & metrics server does not come default with the Minikube installation. But it is available as a minikube addon. Also, if you want to add a custom docker registry to minikube, you have to install the
registry-creds addon and configure it.
By default, only the storage class addons get installed.
You can list all the available add-ons using the following command.
minikube addons list
You can enable an addon from the list using the enable flag.
For example, I am going to enable two addons. Kubernetes dashboard and the kubernetes metrics server.
minikube addons enable dashboard minikube addons enable metrics-server
Access Minikube Kubernetes Dashboard
Once the dashboard addon is enabled you can access the Kubernetes dashboard using the minikube command.
The following command will open the Kubernetes dashboard directly in the browser.
If you just want the dashboard URL, execute the following command. It will start the proxy and displays the Kubernetes dashboard URL in the output.
minikube dashboard --url
You can access the dashboard from the browser as shown below.
Minikube Custom CPU & Memory
By default, Minukube assigns 2 vCPU and 2048 memory. Often times we need extra CPU and memory than the default values set by minikube. To override default CPU and memory limits, you can explicitly specify the custom CPU and memory limits as shown below.
minikube start --driver=virtualbox --memory 3000 --cpus 2
If you want to change the CPU and memory of the existing minikube, execute the following commands with custom CPU and memory values.
minikube stop minikube config set memory 2500 minikube config set cpus 2 minikube start
Note: It does not work with all the drivers. Few drivers like Virturalbox needs a delete before increasing CPU and memory.
Running Multiple Minikube Clusters using Profiles
You can have multiple minikube cluster instances in your workstation using minikube profiles. To create a cluster with a profile, you just need to create the clusters with a profile flag and a profile name.
For example, the following command creates a minikube cluster with the profile name
minikube start -p dev
You can list all the profiles using the list command.
minikube profile list
You should get an output with all the minikube profiles with information like node IP, driver, runtime, status, etc.
You can delete a minikube profile using the following command. It deletes all the configurations related to the profile.
minikube delete -p stage
Switch Between Minikube Profiles
If you have multiple active minikube profiles, you can switch between profiles or set default profile using the minikube command.
For example, to switch to the dev profile, execute the following command. It automatically switched the kubectl context to the dev cluster.
minikube profile dev
To determine the current profile, just run the following command.
If you don’t set up a profile, you might get the following error.
Profile "minikube" not found. Run "minikube profile list" to view all profiles
Either you can set the profile or pass the profile flag with all minikube commands.
minikube service list -p dev
Running Multi-Node Minikube Cluster
You can run a multi-node cluster with minkube. All you have to do is pass a
--nodes flag with the required number of nodes.
For example, to start a 2-node minikube cluster,
minikube start --nodes 2
You can check the node status using the following command.
Access Minikube Nodes (SSH)
If you want to access the minikube node for checking Kubernetes configurations or for rebuffing purposes, you can ssh into the node using the following command.
To open any files inside the node, use
If you have multiple minikube nodes, you can use the specific node to ssh. First you need to list the available nodes using kubectl.
kubectl get nodes
Then use the node name as follows.
minikube ssh -n worker-01
Following are some of the open-source minikube alternatives to have a local kubernetes setup. Do give it a try.
- Kind: https://kind.sigs.k8s.io/
- k3s: https://github.com/k3s-io/k3s
- Autok3s: https://github.com/cnrancher/autok3s
- K0s: https://github.com/k0sproject/k0s
- MicroK8s: https://github.com/ubuntu/microk8s
But only Minkube has support options to work with Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMWare.
What is minikube used for?
Minikube is a local kubernetes setup primarily used for development and testing purposes. It is a lightweight setup that works with tools like Docker, Virtualbox, etc.
How do I view the minikube dashboard?
To access the minikube dashboard, you need to enable the minikube dashboard addon. Then you can access the dashboard from the browser using the minikube command.
How do I deploy an application in minikube?
You can deploy applications in minikube using kubectl like you deploy applications in any Kubernetes cluster.
Can Minikube have multiple clusters in a single workstation?
Yes. Using minikube profiles, you can run multiple instances of minikube cluster instances in a single workstation.
How to use a custom Docker registry with Minikube?
If you are on a corporate network, you might have to use a private docker registry with minikube. To use a custom private docker registry, you should install the registry-creds Minikube addon and configure the registry details.
In this kubernetes minikube tutorial, I have covered the basic minikube setup and steps to deploy an application and access it.
Minikube is a lightweight kubernetes setup you can use to develop and test applications on Kubernetes. Also, with add-ons, you can extend it for advanced features.
I will keep updating this tutorial with the required functionalities of minikube that you can use for your local development and testing.