Kubernetes has become the go-to container orchestration platform for deploying, scaling, and managing applications. However, setting up a full-scale Kubernetes cluster can be complex, especially for local development. That’s where Minikube comes in! Minikube allows you to run a lightweight Kubernetes cluster locally, perfect for development and testing purposes.
In this Blog, I’ll walk through the steps to set up a local Kubernetes cluster using Minikube, ensuring that you can start experimenting with Kubernetes in no time.
What is Minikube?
Minikube is a tool that sets up a single-node Kubernetes cluster on your local machine. It supports multiple container runtimes like Docker, containerd, and CRI-O, and it’s an excellent option for developers who want to test Kubernetes deployments before pushing them to production.
Prerequisites
Before we dive into the setup process, you’ll need:
- A machine with at least 2 CPUs and 2GB of RAM
- A hypervisor like VirtualBox or Hyper-V (if using Windows)
- kubectl (Kubernetes CLI tool)
- Minikube
Step 1: Install Minikube
First, you need to install Minikube on your machine. The installation process varies depending on your operating system. Follow these instructions based on your platform:
For macOS (via Homebrew):
brew install minikube
For Linux (via curl):
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
For Windows (via Chocolatey):
choco install minikube
Step 2: Install kubectl
The Kubernetes command-line tool, kubectl, is essential for interacting with the cluster.
For macOS (via Homebrew):
brew install kubectl
For Linux:
sudo apt-get install -y kubectl
For Windows (via Chocolatey):
choco install kubernetes-cli
Step 3: Start Minikube
Once Minikube is installed, start it with the following command:
minikube start
This command automatically sets up a Kubernetes cluster using the hypervisor installed on your machine (VirtualBox, Hyper-V, Docker, etc.). You can also specify the driver using the --driver
flag, like so:
minikube start --driver="ANY REQUIRED"
Note: By default, Minikube will use Docker as the container runtime. If you prefer containerd or CRI-O, you can specify it with the required flag
Step 4: Verify the Setup
After Minikube has started, you can verify that your cluster is running by checking the nodes in the cluster:
kubectl get nodes
Step 5: Deploy an Application on Minikube
Now that Minikube is running, let’s deploy a simple application. We’ll use a sample NGINX deployment to demonstrate.
First, create a Kubernetes deployment:
kubectl create deployment nginx --image=nginx
Verify that the deployment has been created:
kubectl get deployments
Step 6: Expose the Application
By default, the NGINX deployment is not accessible from outside the cluster. To expose it, we’ll create a service:
kubectl expose deployment my-nginx --port=80
Step 7: Access the Application
Now that the service is exposed, you can access the NGINX web server using Minikube’s IP. To get the Minikube IP, run:
minikube ip: 19X.XXX.XXX.XXX:PORT
Combine this IP with the NodePort value from the previous step to access the application in your browser:

Step 8: Stop the Cluster
Once you’re done experimenting, you can stop the Minikube cluster using the following command:
minikube stop
If you want to delete the cluster entirely, run:
minikube delete
Conclusion
Minikube is a fantastic tool for local Kubernetes development, offering a quick and easy way to spin up a local cluster. In this Blog, we went through the setup process, deployed a simple application, and exposed it for external access. Now you can start experimenting with Kubernetes features and workflows in a local environment before deploying them to a production environment.
Start your Kubernetes journey with Minikube today, and happy developing!
No comments:
Post a Comment