DEV Community

Ajeet Singh Raina
Ajeet Singh Raina

Posted on

Setting up a Local Kubernetes Cluster using Minikube

Kubernetes has emerged as a leading container orchestration platform, enabling organizations to manage and scale their applications efficiently. To experiment, develop, or test Kubernetes locally, Minikube comes to the rescue. Minikube is a lightweight tool that allows you to run a single-node Kubernetes cluster on your local machine. In this guide, we'll explore the step-by-step process of setting up a local Kubernetes cluster using Minikube.

Step 1: Prerequisites

Before diving into the setup process, ensure that your local machine meets the following prerequisites:

  • Virtualization: Verify that virtualization is enabled on your machine. Minikube relies on virtualization technologies like VirtualBox, Hyper-V, or KVM to run the Kubernetes cluster.

  • Hypervisor: Choose a hypervisor that suits your environment. VirtualBox is a popular choice for most platforms, but alternatives like Hyper-V (Windows) or KVM (Linux) can also be used.

  • Minikube: Download and install the latest version of Minikube, which is available for various operating systems. Ensure that the Minikube binary is added to your system's PATH.

Installing Minikube on your Macbook

To install the latest minikube stable release on x86-64 macOS using binary download:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube
Enter fullscreen mode Exit fullscreen mode
  • kubectl: Install the kubectl command-line tool, which is used to interact with the Kubernetes cluster. Ensure that kubectl is also added to your system's PATH.

Step 2: Starting Minikube

Once you've met the prerequisites, you're ready to start the Minikube cluster. Follow these steps:

Open a terminal or command prompt and execute the following command to start Minikube:

minikube start
😄  minikube v1.30.1 on Darwin 13.2.1 (arm64)
✨  Using the docker driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🤷  docker "minikube" container is missing, will recreate.
🔥  Creating docker container (CPUs=2, Memory=4000MB) ...
🐳  Preparing Kubernetes v1.26.3 on Docker 23.0.2 ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  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

This command initializes and starts the Minikube cluster using the default configuration. Minikube will automatically detect and use the appropriate hypervisor based on your environment.

Minikube will download the required ISO image and spin up a virtual machine to host the Kubernetes cluster. The first start may take some time as it needs to download the necessary components.

Once the cluster is up and running, you'll see the confirmation message that Minikube is ready to use.

Step 3: Verifying the Cluster

To verify that the Minikube cluster is running correctly, execute the following command:

kubectl cluster-info
Kubernetes control plane is running at https://127.0.0.1:51807
CoreDNS is running at https://127.0.0.1:51807/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Enter fullscreen mode Exit fullscreen mode

Image10

This command displays information about the Kubernetes cluster, including the cluster endpoint and the Kubernetes version. If everything is set up correctly, you should see the cluster details.

Step 4: Interacting with the Cluster

Now that the Minikube cluster is running, you can start interacting with it using kubectl. Here are a few essential kubectl commands to get you started:

List Nodes:

kubectl get nodes
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   18d   v1.26.3
Enter fullscreen mode Exit fullscreen mode

This command displays information about the nodes in the cluster. In our case, it will show a single node running in the Minikube cluster.

Deployments:

kubectl get deployments

Enter fullscreen mode Exit fullscreen mode

Use this command to list all the deployments in the cluster. Initially, there will be no deployments.

Pods:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

This command lists all the pods running in the cluster. Since we have just started the cluster, no pods will be present initially.

Step 5: Running Applications

Now that the cluster is up and running, you can deploy applications and services. Let's start by deploying a sample application:

Create a Deployment:

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

This command creates a deployment named "hello-minikube" using the "echoserver" image.

Expose the Deployment:

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

This command creates a service to expose the deployment using a NodePort type, which makes it accessible from outside the cluster.

Access the Application:

minikube service hello-minikube
|-----------|----------------|-------------|---------------------------|
| NAMESPACE |      NAME      | TARGET PORT |            URL            |
|-----------|----------------|-------------|---------------------------|
| default   | hello-minikube |        8080 | http://192.168.49.2:30435 |
|-----------|----------------|-------------|---------------------------|
🏃  Starting tunnel for service hello-minikube.
|-----------|----------------|-------------|------------------------|
| NAMESPACE |      NAME      | TARGET PORT |          URL           |
|-----------|----------------|-------------|------------------------|
| default   | hello-minikube |             | http://127.0.0.1:51926 |
|-----------|----------------|-------------|------------------------|
🎉  Opening service default/hello-minikube in default browser...
❗  Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
Enter fullscreen mode Exit fullscreen mode

This command opens a browser window or prints the URL that can be used to access the deployed application. Click the URL or copy it into a web browser to see the running application.

Step 6: Cleaning up

Once you are done experimenting with the Minikube cluster, you can clean up the resources to free up system resources. Execute the following commands:

Delete the service:

kubectl delete service hello-minikube
Enter fullscreen mode Exit fullscreen mode

Delete the deployment:

kubectl delete deployment hello-minikube
Enter fullscreen mode Exit fullscreen mode

Stop the Minikube cluster:

minikube stop
Enter fullscreen mode Exit fullscreen mode

This command stops the running Minikube cluster, but it keeps the virtual machine intact.

Delete the Minikube cluster:

minikube delete
Enter fullscreen mode Exit fullscreen mode

This command deletes the Minikube cluster and removes the associated virtual machine.

Conclusion

Setting up a local Kubernetes cluster using Minikube is a straightforward process that allows you to experiment with Kubernetes concepts and deploy applications locally. Minikube provides a convenient and lightweight environment to develop and test your Kubernetes deployments. By following the steps outlined in this guide, you can quickly get started with Kubernetes on your local machine using Minikube and begin exploring the vast possibilities of container orchestration. Happy Kubernetting!

Top comments (0)