Running Docker on Kubernetes
Learn to run Kubernetes locally for development and testing. This guide covers minikube, kind (Kubernetes in Docker), Docker Desktop Kubernetes, and comparison of local Kubernetes distributions.
Running Kubernetes locally is essential for development, testing, and learning. It allows you to develop and test containerized applications in an environment that closely resembles production, without the cost and complexity of a cloud-based cluster.
Local Kubernetes distributions provide a lightweight, single-node cluster that runs on your development machine. They support the same APIs and features as full Kubernetes, making them ideal for CI/CD pipelines, local testing, and learning Kubernetes concepts.
| Tool | Requirements | Best For | Multi-Node |
|---|---|---|---|
| minikube攀 | VM or Docker (any OS)攀 | Learning, full K8s features | Yes |
| kind攀 | Docker only (Linux/WSL) | CI/CD, fast clusters | Yes |
| Docker Desktop攀 | Docker Desktop | Docker users, convenience | No |
| k3s攀 | Linux only (lightweight) | Edge, IoT, resource-constrained | Yes |
| MicroK8s攀 | Linux (snap) | Ubuntu users, production-ready | Yes |
Minikube is the most popular local Kubernetes distribution. It runs a single-node cluster inside a VM (VirtualBox, Hyper-V, or KVM) or directly on Docker. Minikube supports most Kubernetes features including ingress, storage, and dashboard.
# Install minikube (macOS)
brew install minikube
# Install minikube (Linux)
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Install minikube (Windows)
choco install minikube
# Start cluster
minikube start
# Start with specific driver
minikube start --driver=docker
minikube start --driver=virtualbox
# Start with more resources
minikube start --cpus=4 --memory=8192 --disk-size=20g
# Enable addons
minikube addons enable ingress
minikube addons enable dashboard
minikube addons enable metrics-server
# Access dashboard
minikube dashboard
# Get cluster info
kubectl cluster-info
# Stop cluster
minikube stop
# Delete cluster
minikube delete
Kind runs Kubernetes clusters inside Docker containers. It's extremely fast to start and ideal for CI/CD pipelines. Kind supports multi-node clusters and is compliant with CNCF Kubernetes conformance.
# Install kind (macOS)
brew install kind
# Install kind (Linux)
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
# Install kind (Windows)
choco install kind
# Create single-node cluster
kind create cluster
# Create multi-node cluster with config file
cat <
Docker Desktop includes a built-in Kubernetes cluster. This is the easiest option for Docker users since Kubernetes is just a checkbox in settings. It runs a single-node cluster and integrates seamlessly with Docker commands.
# Enable Kubernetes in Docker Desktop (GUI)
# Docker Desktop -> Settings -> Kubernetes -> Enable Kubernetes -> Apply & Restart
# Verify Kubernetes is running
kubectl cluster-info
kubectl get nodes
# Switch to Docker Desktop context
kubectl config use-context docker-desktop
# Default context for Docker Desktop
kubectl config get-contexts
# Reset Kubernetes cluster
# Docker Desktop -> Troubleshoot -> Reset Kubernetes cluster
# Disable Kubernetes (if not needed)
# Docker Desktop -> Settings -> Kubernetes -> Uncheck Enable Kubernetes
K3s is a lightweight, certified Kubernetes distribution from Rancher. It's designed for resource-constrained environments like edge computing, IoT, and CI/CD. K3s is packaged as a single binary and uses sqlite3 instead of etcd.
# Install k3s (Linux)
curl -sfL https://get.k3s.io | sh -
# Check kubeconfig
sudo cat /etc/rancher/k3s/k3s.yaml
# Use kubectl
sudo kubectl get nodes
# K3s with Docker instead of containerd
curl -sfL https://get.k3s.io | sh -s - --docker
# Install with specific version
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.27.1+k3s1 sh -
# Install k3s on macOS
brew install k3d
k3d cluster create mycluster
# Uninstall k3s
/usr/local/bin/k3s-uninstall.sh
MicroK8s is a snap package from Canonical that runs a full Kubernetes cluster on Linux. It's designed for developers who want a production-like environment locally. MicroK8s includes addons for Istio, Knative, Prometheus, and more.
# Install microk8s (Ubuntu/Linux)
sudo snap install microk8s --classic
# Add user to microk8s group
sudo usermod -a -G microk8s $USER
newgrp microk8s
# Check status
microk8s status --wait-ready
# Enable addons
microk8s enable dashboard dns registry istio
# Access dashboard
microk8s dashboard-proxy
# Use kubectl
microk8s kubectl get nodes
# Alias for convenience
alias kubectl='microk8s kubectl'
# Stop/start cluster
microk8s stop
microk8s start
# Reset cluster
microk8s reset
Once your local cluster is running, you can deploy applications using kubectl. Here's an example of deploying a Docker image to your local Kubernetes cluster.
# Create a deployment
kubectl create deployment nginx --image=nginx:alpine
# Expose the deployment as a service
kubectl expose deployment nginx --port=80 --type=NodePort
# Check service and get port
kubectl get svc
# For minikube: get URL
minikube service nginx --url
# For kind: port-forward
kubectl port-forward svc/nginx 8080:80
# For Docker Desktop: use localhost (NodePort)
# NodePort is typically in range 30000-32767
# Scale deployment
kubectl scale deployment nginx --replicas=3
# Update image
kubectl set image deployment/nginx nginx=nginx:1.25
# Rollout status
kubectl rollout status deployment/nginx
# Delete deployment and service
kubectl delete service nginx
kubectl delete deployment nginx
Each local Kubernetes distribution handles local images differently. Here's how to use images you've built locally:
# For minikube: Use minikube's Docker daemon
eval $(minikube docker-env)
docker build -t myapp:latest .
# Now myapp:latest is available in minikube
# For kind: Load image into cluster
docker build -t myapp:latest .
kind load docker-image myapp:latest
# For Docker Desktop: Images are automatically available
# Docker Desktop uses the same Docker daemon
# For k3s with Docker driver
# Images are automatically available if built with same Docker
# Alternative: Use imagePullPolicy: Never
apiVersion: v1
kind: Pod
spec:
containers:
- name: myapp
image: myapp:latest
imagePullPolicy: Never
Most local Kubernetes distributions support ingress controllers. Here's how to enable them:
# minikube: Enable ingress addon
minikube addons enable ingress
# kind: Install NGINX ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# Docker Desktop: Install NGINX ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml
# Example ingress resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
spec:
rules:
- host: myapp.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 80
# For minikube: Add to /etc/hosts
echo "$(minikube ip) myapp.local" | sudo tee -a /etc/hosts
- Match production version - Use the same Kubernetes version locally as in production.
- Use namespaces - Isolate different projects or environments.
- Don't commit local configs - Keep kubeconfig files out of version control.
- Use krew plugins - Extend kubectl with plugins like `kubectl ns` and `kubectl ctx`.
- Use k9s or Lens - GUI tools make local cluster management easier.
- Clean up regularly - Delete old clusters and resources to save disk space.
- Use Helm for local charts - Test Helm charts locally before deploying to production.
- Enable metrics-server - For `kubectl top` commands to work.
Local Kubernetes distributions make it easy to develop and test containerized applications. Choose the right tool for your workflow and start building cloud-native apps today.