How to create a Kubernetes cluster locally with Minikube

Kubernetes has emerged as a key player in development services, revolutionizing the deployment and management of containerized applications. For developers seeking hands-on experience with Kubernetes without the complexity of a full-scale cluster, Minikube proves to be an invaluable tool. In the upcoming sections, we will delve into the utility of Minikube, highlighting its importance and providing step-by-step guidance on creating a local Kubernetes cluster with this invaluable tool.

Kubernetes

Kubernetes, often abbreviated as K8s, is a powerful open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It enables users to declaratively define and deploy applications, offering features like automated load balancing, self-healing, and dynamic scaling.

Minikube

Minikube is an open-source tool that simplifies the setup of a single-node Kubernetes cluster on a local machine. It’s ideal for developers who want a lightweight solution to experiment, develop, and test applications in a Kubernetes environment without needing a full-scale cluster. Supporting various hypervisors, Minikube enables quick deployment of a Kubernetes cluster on a local system, offering a convenient way to gain hands-on experience with container orchestration and Kubernetes features for local development and learning purposes.

Prerequisites

Before creating a cluster with Minikube, make sure that the following prerequisites are fulfilled:

  • Virtualization software: Let’s ensure we have a virtualization solution installed, such as VirtualBox, KVM, or Hyper-V, depending on our operating system.

  • Docker: Make sure that Docker has been installed and is running.

  • kubectl: Install kubectl, the command-line tool for Kubernetes, by following the instructions on the official Kubernetes documentationhttps://kubernetes.io/docs/home/.

  • Minikube: Download and install Minikube from the official websitehttps://minikube.sigs.k8s.io/docs/, selecting the version compatible with our operating system.

Verification

Before we proceed with the cluster creation, let’s make sure that all our required conditions (i.e., Docker is running, kubectl is installed, and Minikube is also installed) are satisfied by running the following commands:

docker ps -a
kubectl version --client
minikube version

Create a Minikube cluster

To create a Minikube cluster, follow the steps provided below:

1. Start Minikube

Open a terminal or command prompt and execute the following command to start Minikube. This command will automatically create a cluster for us.

minikube start
Starting Minikube

2. Check Minikube status

Confirm the status of our Minikube cluster with:

minikube status
Get the status of Minikube

3. Configure kubectl

Ensure that kubectl is configured to use Minikube’s context. If not, execute the following command:

kubectl config use-context minikube
Configuring kubectl to use the Minikube context

4. Interact with the cluster

Execute the following command to interact with our cluster. This command will retrieve and display the information about the nodes in our cluster:

kubectl get nodes
Get the list of nodes

5. Explore Kubernetes dashboard (optional)

Minikube comes with a built-in dashboard for a graphical interface. Open it in your default web browser:

minikube dashboard
Opens the Minikube dashboard

Conclusion

Creating a local Kubernetes cluster with Minikube simplifies hands-on experimentation for developers. It provides a lightweight solution for learning Kubernetes, bridging the gap between local development and production deployment.

Copyright ©2024 Educative, Inc. All rights reserved