Kubernetes Minikube Tutorial for Beginners

Kubernetes Minikube Tutorial

In this Kubernetes Minikube tutorial, I will go through the required steps for a beginner to get started with Minikube.

In this Minikube beginner tutorial, we will look at the following.

Minikube Prerequisites

Following are the prerequisites for Minikube to work properly.

  1. 2 CPUs or more
  2. 2GB of free memory
  3. 20GB of free disk space
  4. A good Internet connection
  5. Container or virtual machine manager, such as: DockerHyperkitHyper-VKVMParallelsPodmanVirtualBox, or VMWare. Ensure you install any of the tool before you start with Minikube installation.

Note: I recomend installing Virtualbox as the backend minikube driver. It works without any issues.

Installing MiniKube

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.

minikube version

Start Minikube With Virtualbox

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 Virtualbox driver. There will not be any issue with NodePort services if you use the Virtualbox driver.

minikube start --driver=virtualbox

Here we are specifically mentioning --driver=virtualbox because, by default, it picks 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 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.

minikube status

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.

  1. A configmap with custom nginx html
  2. Nginx deployment
  3. 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 directly 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 nginx-service

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.

minikube ip

For example,

http://192.168.99.100:32000

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 NodePort. Where 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.

Minikube Addons

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.

minikube dashboard

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 kubernetes dashboard

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 dev.

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 using the minikube command.

For example, to switch to 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.

minikube profile

If you don’t set 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.

For example,

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.

minikube status

Minikube Alternatives

Following are some of the open-source minikube alternatives to have a local kubernetes setup. Do give it a try.

  1. Kind: https://kind.sigs.k8s.io/
  2. k3s: https://github.com/k3s-io/k3s
  3. Autok3s: https://github.com/cnrancher/autok3s
  4. K0s: https://github.com/k0sproject/k0s
  5. MicroK8s: https://github.com/ubuntu/microk8s

But only minkube has support options to work with Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMWare.

Minikube FAQs

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.

Conclusion

In this kubernetes minikube tutorial, I have covered the basic minikube setup and steps to deploy an application and access it over.

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.

0 Shares:
2 comments
Leave a Reply

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

You May Also Like