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.

minikube kind Docker Desktop k3s
Why Run Kubernetes Locally?

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.

Local Kubernetes is perfect for development, but never use local distributions in production. They are designed for single-node development only.
Local Kubernetes Distribution Comparison
Tool Requirements Best For Multi-Node
minikubeVM or Docker (any OS)攀 Learning, full K8s features Yes
kindDocker only (Linux/WSL) CI/CD, fast clusters Yes
Docker DesktopDocker Desktop Docker users, convenience No
k3sLinux only (lightweight) Edge, IoT, resource-constrained Yes
MicroK8sLinux (snap) Ubuntu users, production-ready Yes
Minikube: The Classic Local Kubernetes

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
Minikube supports multiple profiles, allowing you to run different Kubernetes versions simultaneously.
Kind: Kubernetes in Docker

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 <
Kind clusters start in seconds, making them perfect for CI/CD pipelines and testing Kubernetes operators.
Docker Desktop Kubernetes

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
Docker Desktop Kubernetes uses the same Docker daemon, so `docker images` lists images available to your cluster. No need to push images to a registry.
K3s: Lightweight Kubernetes for Edge

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: Ubuntu's Production-Ready K8s

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
Deploying an Application to Local Kubernetes

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
Working with Local Docker Images

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
Setting Up Ingress Locally

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
Best Practices for Local Kubernetes
  • 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.
Frequently Asked Questions
Which local Kubernetes tool should I use for learning?
Start with minikube. It has the best documentation, most features, and works on all operating systems. Use Docker Desktop Kubernetes if you already use Docker Desktop.
Which tool is fastest for CI/CD?
Kind (Kubernetes in Docker) starts in seconds and is ideal for CI/CD pipelines. It's lightweight and doesn't require a VM.
Can I run multi-node clusters locally?
Yes! Minikube and kind support multi-node clusters. Use `minikube start --nodes=3` or create a kind config file with multiple nodes. Docker Desktop is single-node only.
How much RAM/CPU do I need for local Kubernetes?
Minimum: 2GB RAM, 2 CPU cores. Recommended: 4GB RAM, 4 CPU cores. For multi-node, increase accordingly. K3s uses fewer resources.
Do I need a cloud provider for Kubernetes development?
No! Local Kubernetes is perfect for development. Use cloud providers only for production or when testing cloud-specific features like load balancers.
How do I access services running in local Kubernetes?
Use port-forwarding (`kubectl port-forward`), NodePort services (minikube: `minikube service`), or ingress with local DNS.
Can I use GPU acceleration with local Kubernetes?
Yes, with minikube and the GPU addon. Requires NVIDIA drivers and Docker with GPU support. Not supported in kind or Docker Desktop Kubernetes.
What's the difference between k3s and k3d?
k3s is a lightweight Kubernetes distribution. k3d runs k3s clusters inside Docker containers. k3d is similar to kind but uses k3s instead of standard Kubernetes.
Previous: Rootless Docker Next: Kubernetes Architecture

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.