top of page
Search

Minikube - one of the best local Kubernetes clusters for learning and developing

Updated: Jul 29


Minikube provides a convenient solution for Kubernetes development by offering a local cluster environment. Unlike setting up a new Kubernetes cluster, minikube creates a single node cluster within a virtual machine (VM). This setup facilitates learning and development for Kubernetes, allowing users to experiment with Kubernetes operations without the overhead of installing a full-scale Kubernetes environment, thereby saving time and resources.


Kubernetes Concepts

To help you get started with minikube, it helps to understand some basic k8s concepts. Below are the most basic aspects you should know:

  • Container image: A ready-to-run software package containing everything needed to run an application: the code and any runtime it requires, application and system libraries, and default values for any essential settings.

  • Container: A running instance of your application built from the Container image.

  • Pod: A group of Containers, and is the smallest unit that Kubernetes administers. Containers in a pod share the same resources such as memory and storage.

  • Node: A worker machine, virtual or physical machine that contains the services necessary to run containerized applications. It hosts the Pods and includes kubelet, kube-proxy, container runtime.

  • Cluster: A set of worker machines, called Nodes that run containerized applications. Every cluster has at least one worker node. The workers run your workloads and the control plane orchestrates the workers together. This is what is created by minikube.

  • Control plane: A set of components include API servers, ectd, Scheduler, Controller manager , Cloud Controller Manager. It exposes the API and interfaces to define, deploy, and manage the lifecycle of Containers. For example, we uses kubectl and then the requests are made to this.

  • Deployment: The overall processes that enable you to orchestrate our resources, define the scale at which how pods replicated on Node. It describe the number of desired identical Pod replicas to run. It will track Pod health, and will remove or add Pods as needed to bring your application deployment to the desired state.

  • Service: A method for exposing a network application that is running as one or more Pods in your cluster. So no matter how many Pods are destroyed or recreated to keep the desire state. Service still ensures that the network traffic can be directed to current set of Pods for the workload.

This video greatly demonstrates how it works:


Install minikube

Prerequisites:


Installing on Windows

To simplify the process, I suggest you to install Chocolatey Package Manager, then use following command:

choco install minikube

Installing on MacOS

If Homebrew Package Manager is installed, do the following command:

brew install minikube

If command which minikube fails after installation via brew, you may have to remove the old minikube links and link the newly installed binary:

brew unlink minikube
brew link minicube

Verify installation

To confirm if minikube is installed successfully:

minikube version

For other installation in Linux or by downloading .exe in Windows and downloading binary in MacOS, please head to original document minikube installation.


Install kubectl

kubectl allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. For more information including a complete list of kubectl operations, see the kubectl reference documentation.


Installing on Windows

If you have Chocolatey Package Manager already, then use following command:

choco install kubernetes-cli

Check the version you installed is up-to-date:

kubectl version --client

Navigate to home directory:

# If you are using cmd, run cd %USERPROFILE#
cd ~

Create .kube directory:

mkdir .kube

Change to the .kube directory you just created:

cd .kube

Configure kubectl to use a remote Kubernetes cluster, below for Powershell:

New-Item config -type file

For other way of installing in Windows, please head to install kubectl for Windows.


Installing on MacOS

If Homebrew Package Manager is installed, do the following command:

brew install kubectl
# or
brew install kubernetes-cli

Check the version you installed is up-to-date:

kubectl version --client

For other way of installing in MacOS, please head to install kubectl for MacOS.


Installing on Linux

For Linux, please head to install kubectl for Linux.


Install driver

minikube can be deployed as a VM, a container, or bare-metal.

So we need to have supported VM or container manager to have our minikube deployed.


In this scope of this instruction, the container I'm going to use is Docker Desktop -  a secure, out-of-the-box containerization software offering developers and teams a robust, hybrid toolkit to build, share, and run applications anywhere.


Prerequisites:

Start a cluster using the docker driver:

minikube start --driver=docker

To make docker the default driver (optional):

minikube config set driver docker

List of supported driver can be found here supported drivers.


List of useful commands

Manage cluster life cycle

We have already set up driver = docker, so don't need to explicitly specify it again when starting minikube:

minikube start

After cluster started, verify its status:

minikube status

To pause the cluster:

minikube pause

Un-pause the cluster:

minikube unpause

Stop a cluster:

minikube stop

Delete a cluster - this will delete a cluster completely and all configs belongs to cluster will be deleted:

minikube delete

Mange via dashboard

minikube supports the native Kubernetes dashboard, to open it in a new page:

minikube dashboard

The minikube dashboard is web-based UI for cluster management and application deployment. It offers an overview of cluster operations, streamlining resource modification, monitoring, and error investigation.


Using addons

Addons are extensions of minikube that users can enable or disable to access advanced features. These features include the dashboard, registry credentials, or ingress. Users can leverage pre-existing addons or customize them by modifying the associated YAML file.


To see what addons are available and if they are enabled:

minikube addons list 

To enable or disable an addon:

minikube addons enable <ADDON_NAME>
// or
minikube addons disable <ADDON_NAME>

Managing Ingress

By default, minikube doesn’t provide an ingress controller. For basic experimentation with Kubernetes features, ingress isn’t really necessary.

However, ingress becomes necessary in most cases if you want to test how real-world applications might behave, because ingress helps you simulate the networking conditions that those applications would experience when running in a production cluster.

Fortunately, minikube provides addons that make it easy to install an ingress controller. You can do this with a simple command:

minikube addons enable ingress

This creates an NGINX-based ingress controller for your minikube environment.

It doesn’t support complex ingress configurations. You’ll need a full-fledged complex Kubernetes distribution for testing advanced networking setups. But for basic application testing, minikube and its NGINX ingress addon should suffice.


Verify that the NGINX Ingress controller is running:

kubectl get pods -n ingress-nginx

The output is similar to:

NAME                                        READY   STATUS      RESTARTS    AGE
ingress-nginx-admission-create-g9g49        0/1     Completed   0          11m
ingress-nginx-admission-patch-rqp78         0/1     Completed   1          11m
ingress-nginx-controller-59b45fb494-26npt   1/1     Running     0          11m

Deploy an example application

Create a sample deployment:

kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0

Create a service and expose it to external traffic:

kubectl expose deployment hello-minikube --type=NodePort --port=8080

Your deployment will soon show up when you run:

kubectl get services hello-minikube
Due to Docker Desktop networking limitations, by default you’re unable to access pods directly from the host. Below command will create a SSH tunnel from the pod to your host and open a window in your default browser that’s connected to the service.

The easiest way to access this service is to let Minikube launch a web browser for you:

minikube service hello-minikube

If you already had added ingress addon, we can visit the service from url:

minikube service hello-minikube -url

Output is similar to:

From a different terminal, invoke the URL obtained in the output of the previous step:

curl http://127.0.0.1:62445 

Alternatively, use kubectl to forward the port:

kubectl port-forward service/hello-minikube 7080:8080

Your application is now available at http://localhost:7080/.


We can delete above service with, but remember that it only deletes service, so the route is not exposed anymore, the deployment is still there (remember to create service again if needed in later steps):

kubectl delete service -l app=hello-minikube

We can update version of application by:

kubectl create deployment hello-minikube --image=kicbase/echo-server:1.1

If some of the Pods have a status of ImagePullBackOff, we should roll back the deployment to your last working version, use the rollout undo command:

kubectl rollout undo deployments/hello-minikube

Interact with cluster with kubectl

To view cluster details:

kubectl cluster-info

To view nodes

kubectl get nodes

To see all available pods:

kubectl get pods -A

To check specific pod details:

kubectl describe pods <POD_NAME>

To start a bash session inside a pod:

kubectl exec -ti <POD_NAME> -- bash

To see all deployments:

kubectl get deployments

To scale up or scale down a deployment, we can specify a number of replicas:

kubectl scale deployments/hello-minikube --replicas=4

To see the ReplicaSet created by the Deployment, run:

kubectl get rs

Conclusion

Main benefits

  • Provides a convenient and isolated environment for testing Kubernetes configurations and deploy applications locally.

  • Ideal for newcomers to Kubernetes, easy to learn and experiment with Kubernetes concepts, APIs, and commands.

  • Supports Windows, macOS, and Linux, ensuring accessibility to a wide developer base.

Drawbacks

  • Isn't intended for production deployments.

  • It focuses on setting up single-node clusters quickly rather than multi-node clusters (although it is possible to do).

  • In production scenarios, Kubernetes clusters are typically deployed on cloud platforms or on-premises data centers to ensure scalability, redundancy, and performance for production-grade applications.

  • It supports basic ingress configurations and minikube's options are limited for complex networking needs.


Overall, minikube provides a straightforward setup process, flexible deployment options, and support for major operating systems, making it a user-friendly tool for Kubernetes experimentation. However, it falls short of being a production-grade Kubernetes distribution and is best suited for those new to containers and Kubernetes.


So that's it. In case you have any question, please leave a comment below, I will try to have a look and answer them. Next post is going to be about Kubernetes, please stay tuned 😆!!!

92 views0 comments

Comments


bottom of page