DEV Community

Cover image for How to Setup a Kubernetes Cluster with Minikube
Onyeanuna prince
Onyeanuna prince

Posted on • Originally published at Medium

How to Setup a Kubernetes Cluster with Minikube

For users that are interested in trying out Kubernetes or developing with it on a regular basis, Minikube runs a single-node Kubernetes cluster in a VM on their laptop.

With Minikube, new Kubernetes developers can master the basics, try out new ideas, and become familiar with the Kubernetes environment.

Rather than using a cloud-based Kubernetes cluster, Minikube allows you to run Kubernetes on local machines. This is useful for testing and development purposes, as well as for learning Kubernetes concepts and features.

In this tutorial, you will learn how to set up a Kubernetes cluster on a local machine.

Prerequisites

Although this tutorial will explain each process in detail, it is recommended that you have a basic understanding of Kubernetes and its concepts.

You will also need to have the following installed on your local machine:

  • Docker: Docker acts as the container runtime and provides the necessary infrastructure for Minikube to create and manage containers within the local Kubernetes cluster.
  • Kubectl: This is the command-line tool used to interact with the local Kubernetes cluster created by Minikube. It allows you to run commands against Kubernetes clusters to deploy applications, inspect and manage cluster resources, and view logs.
  • Hardware requirements: Minikube requires a minimum of 2 CPUs, 2GB of RAM, and 20GB of disk space to run a single-node Kubernetes cluster.

Step 1 — Installing Minikube

The OS used in this tutorial is Ubuntu 20.04, but you can install Minikube on other operating systems as well.

Installing Minikube requires downloading the Minikube binary and installing it on your local system.

Minikube has binary versions for many operating systems and architectures. You can find the binary for any system type by checking the Minikube releases page.

To find out your system architecture type, run the following command:

uname -i
Enter fullscreen mode Exit fullscreen mode

To download the Minikube binary for a x86_64 architecture Ubuntu system, run the following command:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb

sudo dpkg -i minikube_latest_amd64.deb
Enter fullscreen mode Exit fullscreen mode

The output will look like this:

Selecting previously unselected package minikube.
(Reading database ... 65066 files and directories currently installed.)
Preparing to unpack minikube_latest_amd64.deb ...
Unpacking minikube (1.32.0-0) ...
Setting up minikube (1.32.0-0) ...
Enter fullscreen mode Exit fullscreen mode

Run the following command to verify that Minikube has been installed:

minikube version
Enter fullscreen mode Exit fullscreen mode

Step 2 — Starting Minikube

When you start Minikube, it creates a single-node Kubernetes cluster inside a VM on your local machine.

In this case, Minikube will use the Docker container runtime to create and manage containers within the local Kubernetes cluster.

To start Minikube, run the following command:

minikube start
Enter fullscreen mode Exit fullscreen mode

The output will look like this:

😄  minikube v1.32.0 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: none, ssh
📌  Using Docker driver with root privileges
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.28.3 preload ...
    > preloaded-images-k8s-v18-v1...:  403.35 MiB / 403.35 MiB  100.00% 138.82
    > gcr.io/k8s-minikube/kicbase...:  453.90 MiB / 453.90 MiB  100.00% 140.38
🔥  Creating docker container (CPUs=2, Memory=7900MB) ...
🐳  Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
Enter fullscreen mode Exit fullscreen mode

To check the status of the Minikube cluster, run the following command:

minikube status
Enter fullscreen mode Exit fullscreen mode

This will show you the status of the Minikube cluster:

minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Enter fullscreen mode Exit fullscreen mode

This status simply shows that the Minikube cluster is running and the Kubernetes components are up and running.

Step 3 — Interact with the Kubernetes Cluster

At this point, Minikube has started a single-node Kubernetes cluster inside a VM on your local machine.

It also configured the Kubernetes command-line tool, kubectl, to interact with the local Kubernetes cluster.

To view the nodes in the cluster, run the following command:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

You should see only one node - the Minikube node:

NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   77s   v1.28.3
Enter fullscreen mode Exit fullscreen mode

Step 4 — Deploy an Application

Now that you have a running Kubernetes cluster, you can deploy an application to it.

This tutorial will deploy a Kubernetes sample application called hello-minikube.

This application is a simple web server that serves a static web page containing the text "Hello, Minikube!".

To deploy the hello-minikube application, run the following command:

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
Enter fullscreen mode Exit fullscreen mode

The command will create a deployment called hello-minikube and use the k8s.gcr.io/echoserver:1.10 image to create the pods.

Step 5 — Expose the Deployment

Exposing a deployment means making it accessible from outside the Kubernetes cluster.

To expose the hello-minikube application, run the following command:

kubectl expose deployment hello-minikube --type=NodePort --port=8080
Enter fullscreen mode Exit fullscreen mode

This command creates a service of type NodePort that exposes the hello-minikube deployment on a port accessible from outside the cluster.

Step 6 — Access the Application

To access the hello-minikube application, you need to find the URL to access the service.

To find the URL, run the following command:

minikube service hello-minikube --url
Enter fullscreen mode Exit fullscreen mode

The output will look like this:

http://<ip>:<port>
Enter fullscreen mode Exit fullscreen mode

You can access the application by visiting the URL in your web browser.

You can also use the curl command to access the application from the terminal.

curl http://<ip>:<port>
Enter fullscreen mode Exit fullscreen mode

Step 7 — Stopping Minikube

When you are done working with the Minikube cluster, you can stop it by running the following command:

minikube delete
Enter fullscreen mode Exit fullscreen mode

The output will look like this:

🔥  Deleting "minikube" in docker ...
🔥  Deleting container "minikube" ...
🔥  Removing /home/ubuntu/.minikube/machines/minikube ...
💀  Removed all traces of the "minikube" cluster.
Enter fullscreen mode Exit fullscreen mode

This command will stop the Minikube cluster and remove all traces of it from your local machine.

Conclusion

In this tutorial, you learned how to set up a Kubernetes cluster on your computer with Minikube.

You also learned how to deploy an application to the cluster and access it from outside the cluster.

Your journey with Kubernetes has just begun. You are now ready to explore more advanced Kubernetes and Minikube features.

Top comments (0)