Minikube is a powerful tool that allows developers to run Kubernetes clusters locally. It is ideal for development, testing, and learning Kubernetes without the need for a full-scale cluster setup. This tutorial provides a step-by-step guide on how to use Minikube for local Kubernetes development and testing.
Before you start, ensure that your system meets the following minimum requirements to run Minikube:
To get started with Minikube, you need to install it on your local machine. Follow the instructions below to install Minikube on Ubuntu.
1. Update Package List:
sudo apt-get update
2. Install Dependencies:
sudo apt-get install -y apt-transport-https ca-certificates curl
3. Download Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
4. Install Minikube:
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Before starting Minikube, ensure that your environment is set up correctly. This includes installing kubectl, the command-line tool for interacting with Kubernetes clusters.
1. Download kubectl:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
2. Install kubectl:
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
3. Verify Installation:
kubectl version --client
Output:
Minikube requires a driver to manage the VM or container it runs in. You need to install one of the supported drivers listed in the error message.
Did you know?
Modern microservice architectures are commonly deployed using Kubernetes managed services, which simplify upgrades and cluster operations. A reliable Kubernetes service helps teams focus on application logic instead of infrastructure.
1. Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
2. Set up the Docker repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3. Install Docker Engine:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
4. Verify Docker installation:
sudo docker run hello-world
5. Add User to Docker Group
sudo usermod -aG docker $USER newgrp docker
1. Create a non-root user, if you don't already have one:
sudo adduser minikubeuser
Set a password and follow the prompts to complete the user creation process.
2. Add the new user to the Docker group to grant Docker permissions:
sudo usermod -aG docker minikubeuser
3. Switch to the non-root user:
su - minikubeuser
4. Start Minikube with Docker Driver:
minikube start --driver=docker
Output:
5. Verify Minikube Installation:
minikube status
Output:
6. Verify cluster status:
kubectl cluster-info
Output:
After that, check out the Kubernetes Monitoring tutorial—learn how to deploy Prometheus and Grafana add-ons to visualize CPU, memory, and pod metrics right from your desktop.
Deploying an application on Minikube is straightforward. This example demonstrates how to deploy a simple Nginx server.
1. Create Deployment:
kubectl create deployment nginx --image=nginx
2. Expose Deployment:
kubectl expose deployment nginx --type=NodePort --port=80
3. Access the Application:
minikube service nginx --url
Output:
Managing resources in Minikube is similar to managing resources in any Kubernetes cluster.
List all pods:
kubectl get pods
Delete a pod:
kubectl delete pod <pod-name>
Minikube supports several add-ons that can enhance your development and testing experience.
1. List available add-ons:
minikube addons list
2. Enable Add-on:
minikube addons enable <addon-name>
Minikube provides a Kubernetes dashboard that offers a visual interface for managing your cluster.
Start Dashboard:
minikube dashboard
Output:
Effective debugging and logging are crucial for successful development and testing.
Get pod logs:
kubectl logs <pod-name>
When you are done with your development and testing, you can stop and delete your Minikube cluster.
1. Stop Minikube:
minikube stop
2. Delete Minikube
minikube delete
Minikube is a versatile tool for local Kubernetes development and testing. By following this guide, you can set up Minikube, deploy applications, manage resources, and use add-ons to enhance your development experience. Happy coding!