Minikube Essentials
Quick reference guide for Minikube - local Kubernetes development.
What is Minikube?
Minikube is a lightweight Kubernetes implementation that:
Installation
macOS
# ========== Using Homebrew ==========
brew install minikube
# ========== Verify Installation ==========
minikube version
Linux
# ========== Download Binary ==========
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# ========== Verify Installation ==========
minikube version
Windows
# Using Chocolatey
choco install minikube
# Or download installer from:
# https://minikube.sigs.k8s.io/docs/start/
Install kubectl
# ========== macOS ==========
brew install kubectl
# ========== Linux ==========
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# ========== Verify ==========
kubectl version --client
Basic Commands
Cluster Management
# ========== Start Minikube ==========
minikube start
# Start with specific driver
minikube start --driver=docker
minikube start --driver=virtualbox
# Start with specific Kubernetes version
minikube start --kubernetes-version=v1.28.0
# Start with more resources
minikube start --cpus=4 --memory=8192
# ========== Check Status ==========
minikube status
# ========== Stop Minikube ==========
minikube stop
# ========== Delete Cluster ==========
minikube delete
# ========== Pause/Unpause ==========
minikube pause
minikube unpause
# ========== SSH into Node ==========
minikube ssh
# ========== Get Cluster IP ==========
minikube ip
Configuration
# ========== View Config ==========
minikube config view
# ========== Set Default Driver ==========
minikube config set driver docker
# ========== Set Default Resources ==========
minikube config set cpus 4
minikube config set memory 8192
# ========== List Profiles ==========
minikube profile list
# ========== Create New Profile ==========
minikube start -p dev-cluster
# ========== Switch Profile ==========
minikube profile dev-cluster
Working with kubectl
Basic kubectl Commands
# ========== Get Cluster Info ==========
kubectl cluster-info
kubectl get nodes
# ========== Get All Resources ==========
kubectl get all
kubectl get all -A
# ========== Get Pods ==========
kubectl get pods
kubectl get pods -o wide
kubectl get pods -w
# ========== Describe Resources ==========
kubectl describe pod <pod-name>
kubectl describe node minikube
# ========== View Logs ==========
kubectl logs <pod-name>
kubectl logs <pod-name> -f
# ========== Execute Command ==========
kubectl exec -it <pod-name> -- /bin/bash
Deploying Applications
Simple Deployment
# ========== Create Deployment ==========
kubectl create deployment nginx --image=nginx:latest
# ========== Expose Deployment ==========
kubectl expose deployment nginx --port=80 --type=NodePort
# ========== Get Service URL ==========
minikube service nginx --url
# ========== Open in Browser ==========
minikube service nginx
YAML Deployment
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30080
# ========== Apply YAML ==========
kubectl apply -f deployment.yaml
# ========== View Deployment ==========
kubectl get deployments
kubectl get services
# ========== Access Service ==========
minikube service my-app-service
Docker Integration
Using Minikube's Docker Daemon
# ========== Configure Shell ==========
eval $(minikube docker-env)
# This makes your shell use Minikube's Docker daemon
# Now `docker` commands work with Minikube's registry
# ========== Build Image ==========
docker build -t myapp:v1 .
# ========== Deploy Local Image ==========
kubectl run myapp --image=myapp:v1 --image-pull-policy=Never
# ========== Reset to Host Docker ==========
eval $(minikube docker-env -u)
Example: Build and Deploy
# 1. Point to Minikube's Docker
eval $(minikube docker-env)
# 2. Build your application
docker build -t myapp:latest .
# 3. Create deployment (no need to push to registry)
kubectl create deployment myapp --image=myapp:latest --image-pull-policy=Never
# 4. Expose service
kubectl expose deployment myapp --port=8080 --type=NodePort
# 5. Access service
minikube service myapp
Addons
Enable Addons
# ========== List Available Addons ==========
minikube addons list
# ========== Enable Dashboard ==========
minikube addons enable dashboard
minikube dashboard
# ========== Enable Ingress ==========
minikube addons enable ingress
# ========== Enable Metrics Server ==========
minikube addons enable metrics-server
kubectl top nodes
kubectl top pods
# ========== Enable Registry ==========
minikube addons enable registry
# ========== Enable Storage Provisioner ==========
minikube addons enable storage-provisioner
minikube addons enable default-storageclass
# ========== Disable Addon ==========
minikube addons disable dashboard
Popular Addons
# ========== Ingress Controller ==========
minikube addons enable ingress
# ========== Istio Service Mesh ==========
minikube addons enable istio
minikube addons enable istio-provisioner
# ========== Helm (Package Manager) ==========
minikube addons enable helm-tiller
# ========== Logging with EFK ==========
minikube addons enable efk
# ========== Nvidia GPU Support ==========
minikube addons enable nvidia-gpu-device-plugin
Kubernetes Dashboard
# ========== Enable Dashboard ==========
minikube addons enable dashboard
# ========== Open Dashboard ==========
minikube dashboard
# ========== Get Dashboard URL ==========
minikube dashboard --url
# ========== Access Dashboard via Proxy ==========
kubectl proxy
# Then open: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
Ingress
Enable and Configure Ingress
# ========== Enable Ingress Addon ==========
minikube addons enable ingress
# ========== Verify Ingress Controller ==========
kubectl get pods -n ingress-nginx
Example Ingress Configuration
# app-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myapp.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service
port:
number: 80
# ========== Apply Ingress ==========
kubectl apply -f app-ingress.yaml
# ========== Get Ingress IP ==========
kubectl get ingress
# ========== Add to /etc/hosts ==========
echo "$(minikube ip) myapp.local" | sudo tee -a /etc/hosts
# ========== Access Application ==========
curl http://myapp.local
Persistent Storage
Using PersistentVolume
# pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: app-with-storage
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: my-pvc
# ========== Apply PVC ==========
kubectl apply -f pvc.yaml
# ========== Check PVC Status ==========
kubectl get pvc
kubectl get pv
Mounting Host Directory
# ========== Start with Mount ==========
minikube start --mount --mount-string="/host/path:/minikube/path"
# ========== Mount After Start ==========
minikube mount /host/path:/minikube/path
LoadBalancer Services
Using Minikube Tunnel
# ========== Create LoadBalancer Service ==========
kubectl create deployment web --image=nginx
kubectl expose deployment web --port=80 --type=LoadBalancer
# ========== Start Tunnel (in separate terminal) ==========
minikube tunnel
# ========== Get External IP ==========
kubectl get services
# Access via the EXTERNAL-IP shown
# Note: Keep tunnel running while accessing the service
Multi-Node Cluster
# ========== Start Multi-Node Cluster ==========
minikube start --nodes 3
# ========== Add Node to Existing Cluster ==========
minikube node add
# ========== List Nodes ==========
kubectl get nodes
minikube node list
# ========== Delete Node ==========
minikube node delete <node-name>
Common Workflows
Development Workflow
# ========== 1. Start Minikube ==========
minikube start
# ========== 2. Point to Minikube Docker ==========
eval $(minikube docker-env)
# ========== 3. Build Application ==========
docker build -t myapp:dev .
# ========== 4. Deploy Application ==========
kubectl create deployment myapp --image=myapp:dev --image-pull-policy=Never
# ========== 5. Expose Service ==========
kubectl expose deployment myapp --port=8080 --type=NodePort
# ========== 6. Access Application ==========
minikube service myapp
# ========== 7. Update Application ==========
# Make code changes
docker build -t myapp:dev .
kubectl rollout restart deployment myapp
# ========== 8. View Logs ==========
kubectl logs -f deployment/myapp
Testing with ConfigMaps
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
database_url: "postgres://localhost:5432"
log_level: "debug"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myapp:latest
envFrom:
- configMapRef:
name: app-config
# ========== Apply Config ==========
kubectl apply -f configmap.yaml
# ========== Update ConfigMap ==========
kubectl edit configmap app-config
# ========== Restart Deployment ==========
kubectl rollout restart deployment app
Monitoring and Debugging
Resource Usage
# ========== Enable Metrics Server ==========
minikube addons enable metrics-server
# ========== Wait for Metrics ==========
sleep 30
# ========== View Resource Usage ==========
kubectl top nodes
kubectl top pods
kubectl top pods --all-namespaces
# ========== Detailed Node Info ==========
kubectl describe node minikube
Debugging Pods
# ========== Get Pod Details ==========
kubectl describe pod <pod-name>
# ========== View Logs ==========
kubectl logs <pod-name>
kubectl logs <pod-name> --previous
# ========== Stream Logs ==========
kubectl logs -f <pod-name>
# ========== Execute Commands ==========
kubectl exec -it <pod-name> -- /bin/bash
kubectl exec <pod-name> -- env
# ========== Port Forward ==========
kubectl port-forward pod/<pod-name> 8080:80
# ========== Copy Files ==========
kubectl cp <pod-name>:/path/to/file ./local-file
kubectl cp ./local-file <pod-name>:/path/to/file
View Events
# ========== Get Events ==========
kubectl get events --sort-by=.metadata.creationTimestamp
# ========== Watch Events ==========
kubectl get events --watch
# ========== Events for Specific Namespace ==========
kubectl get events -n default
Performance Tuning
Resource Allocation
# ========== Start with More Resources ==========
minikube start --cpus=4 --memory=8192 --disk-size=50g
# ========== Check Current Config ==========
minikube config view
# ========== Delete and Recreate ==========
minikube delete
minikube start --cpus=4 --memory=8192
Driver Selection
# ========== Docker (Fastest, No VM) ==========
minikube start --driver=docker
# ========== VirtualBox (Full VM) ==========
minikube start --driver=virtualbox
# ========== Hyperkit (macOS) ==========
minikube start --driver=hyperkit
# ========== KVM2 (Linux) ==========
minikube start --driver=kvm2
Troubleshooting
Common Issues
# ========== Minikube Won't Start ==========
# Check driver status
minikube status
# Delete and restart
minikube delete
minikube start
# Check logs
minikube logs
# ========== Cannot Access Services ==========
# Check if tunnel is needed
minikube tunnel
# Get service URL
minikube service <service-name> --url
# ========== Pod ImagePullBackOff ==========
# Use local image with correct pull policy
kubectl set image deployment/<name> <container>=<image> --image-pull-policy=Never
# Or point to Minikube Docker
eval $(minikube docker-env)
# ========== Out of Disk Space ==========
# Clean up
minikube ssh
docker system prune -a
# Or increase disk size
minikube delete
minikube start --disk-size=50g
# ========== Reset Everything ==========
minikube delete --all --purge
View Logs
# ========== Minikube Logs ==========
minikube logs
# ========== Last 100 Lines ==========
minikube logs --length=100
# ========== Follow Logs ==========
minikube logs -f
# ========== Component Logs ==========
minikube ssh
sudo journalctl -u kubelet
Best Practices
Development
Resource Management
# Set reasonable defaults
minikube config set cpus 4
minikube config set memory 8192
minikube config set driver docker
# Clean up regularly
kubectl delete pod --field-selector=status.phase==Succeeded
kubectl delete pod --field-selector=status.phase==Failed
Namespace Organization
# Create development namespace
apiVersion: v1
kind: Namespace
metadata:
name: development
---
# Use in deployments
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: development
Quick Commands Cheat Sheet
# ========== Cluster ==========
minikube start # Start cluster
minikube stop # Stop cluster
minikube delete # Delete cluster
minikube status # Check status
minikube dashboard # Open dashboard
# ========== Service Access ==========
minikube service <name> # Open service in browser
minikube service <name> --url # Get service URL
minikube tunnel # Create LoadBalancer tunnel
# ========== Docker ==========
eval $(minikube docker-env) # Use Minikube Docker
eval $(minikube docker-env -u) # Reset to host Docker
# ========== Addons ==========
minikube addons list # List addons
minikube addons enable <name> # Enable addon
minikube addons disable <name> # Disable addon
# ========== Troubleshooting ==========
minikube logs # View logs
minikube ssh # SSH into node
minikube ip # Get cluster IP