How To Use Minikube for Local Kubernetes Development and Testing
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.
Prerequisites Copy link
Before you start, ensure that your system meets the following minimum requirements to run Minikube:
- CPU: At least 2 CPUs
- Memory: Minimum 2GB of RAM (4GB recommended)
- Disk Space: At least 20GB of free disk space
Install Minikube Copy link
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 update2. Install Dependencies:
sudo apt-get install -y apt-transport-https ca-certificates curl3. Download Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd644. Install Minikube:
sudo install minikube-linux-amd64 /usr/local/bin/minikubeSet Up Your Environment Copy link
Before starting Minikube, ensure that your environment is set up correctly. This includes installing kubectl, the command-line tool for interacting with Kubernetes clusters.
Install kubectl
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/kubectl3. Verify Installation:
kubectl version --clientOutput:
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.
Install and configure the Docker driver
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.gpg2. 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/null3. Install Docker Engine:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin4. Verify Docker installation:
sudo docker run hello-world5. Add User to Docker Group
sudo usermod -aG docker $USER newgrp dockerRun Minikube as a non-root user
1. Create a non-root user, if you don't already have one:
sudo adduser minikubeuserSet 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 minikubeuser3. Switch to the non-root user:
su - minikubeuser4. Start Minikube with Docker Driver:
minikube start --driver=dockerOutput:
5. Verify Minikube Installation:
minikube statusOutput:
6. Verify cluster status:
kubectl cluster-infoOutput:
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.
Deploy Your First Application Copy link
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=nginx2. Expose Deployment:
kubectl expose deployment nginx --type=NodePort --port=803. Access the Application:
minikube service nginx --urlOutput:
Managing Minikube Resources Copy link
Managing resources in Minikube is similar to managing resources in any Kubernetes cluster.
List all pods:
kubectl get podsDelete a pod:
kubectl delete pod <pod-name>Using Minikube Add-ons Copy link
Minikube supports several add-ons that can enhance your development and testing experience.
1. List available add-ons:
minikube addons list2. Enable Add-on:
minikube addons enable <addon-name>Accessing Minikube Dashboard Copy link
Minikube provides a Kubernetes dashboard that offers a visual interface for managing your cluster.
Start Dashboard:
minikube dashboardOutput:
Debugging and Logging Copy link
Effective debugging and logging are crucial for successful development and testing.
Get pod logs:
kubectl logs <pod-name>Stopping and Deleting Minikube Copy link
When you are done with your development and testing, you can stop and delete your Minikube cluster.
1. Stop Minikube:
minikube stop2. Delete Minikube
minikube deleteConclusion Copy link
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!