Module 8.3: Local Kubernetes
Цей контент ще не доступний вашою мовою.
Toolkit Track | Complexity:
[QUICK]| Time: 30-35 minutes
Overview
Section titled “Overview”Before you can develop for Kubernetes, you need Kubernetes. But you don’t need a cloud account or a production cluster—you need a local, disposable environment for learning and testing. This module covers kind, minikube, and other local Kubernetes options for development.
What You’ll Learn:
- Local Kubernetes options comparison
- kind for multi-node development clusters
- minikube for feature-rich local K8s
- Docker Desktop Kubernetes for simplicity
Prerequisites:
- Docker installed
- Basic Kubernetes concepts
- Terminal/CLI familiarity
What You’ll Be Able to Do
Section titled “What You’ll Be Able to Do”After completing this module, you will be able to:
- Deploy local Kubernetes clusters using kind, minikube, and Docker Desktop with optimal configurations
- Configure local clusters with ingress controllers, registries, and multi-node topologies for realistic testing
- Implement local development workflows that mirror production Kubernetes environments accurately
- Compare local Kubernetes tools for CI/CD testing, application development, and learning scenarios
Why This Module Matters
Section titled “Why This Module Matters”Cloud Kubernetes costs money and has latency. Local Kubernetes is free and instant. For learning, testing, and development, local clusters are essential. The question isn’t whether to use local K8s—it’s which tool fits your needs.
💡 Did You Know? kind (Kubernetes IN Docker) was originally created to test Kubernetes itself. The Kubernetes project uses kind in its CI/CD to test Kubernetes against Kubernetes. It became so useful that developers adopted it for local development, and now it’s one of the most popular tools for running local clusters.
Tool Comparison
Section titled “Tool Comparison”LOCAL KUBERNETES OPTIONS════════════════════════════════════════════════════════════════════
kind minikube Docker Desktop─────────────────────────────────────────────────────────────────Multi-node ✓✓ ✓ ✗Speed Fast Medium FastResources Low Medium LowGPU support ✗ ✓ ✓LoadBalancer Manual Built-in Built-inIngress Manual Addon ManualContainer runtime Docker Multiple DockerPersistence ✗* ✓ ✓Best for CI/CD, testing Learning, addons Quick start─────────────────────────────────────────────────────────────────
* kind clusters are ephemeral by designWhen to Use What
Section titled “When to Use What”DECISION TREE════════════════════════════════════════════════════════════════════
Need Kubernetes for what?│├── CI/CD testing│ └──▶ kind (fast, ephemeral, multi-node)│├── Learning/tutorials│ └──▶ minikube (addons, good docs)│├── Just need it to work│ └──▶ Docker Desktop (already installed)│├── Multi-node testing│ └──▶ kind (easy multi-node)│├── GPU/ML development│ └──▶ minikube (GPU support)│└── Team standardization └──▶ Any (pick one, share configs)kind (Kubernetes IN Docker)
Section titled “kind (Kubernetes IN Docker)”Installation
Section titled “Installation”# macOSbrew install kind
# Linuxcurl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64chmod +x ./kindsudo mv ./kind /usr/local/bin/kind
# Verifykind versionBasic Usage
Section titled “Basic Usage”# Create clusterkind create cluster
# Create with namekind create cluster --name my-cluster
# List clusterskind get clusters
# Delete clusterkind delete cluster --name my-cluster
# Get kubeconfigkind get kubeconfig --name my-clusterMulti-Node Cluster
Section titled “Multi-Node Cluster”kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane- role: worker- role: worker- role: workerkind create cluster --config kind-config.yamlIngress Setup
Section titled “Ingress Setup”kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane kubeadmConfigPatches: - | kind: InitConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "ingress-ready=true" extraPortMappings: - containerPort: 80 hostPort: 80 protocol: TCP - containerPort: 443 hostPort: 443 protocol: TCP# Create cluster with ingress supportkind create cluster --config kind-config-ingress.yaml
# Install ingress controllerkubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yamlLoading Local Images
Section titled “Loading Local Images”# Build image locallydocker build -t myapp:dev .
# Load into kind clusterkind load docker-image myapp:dev
# Now you can use myapp:dev in your pods# No registry needed!💡 Did You Know? kind runs Kubernetes nodes as Docker containers. This means you can have a 3-node cluster using a few hundred MB of memory, all within Docker. It’s how the Kubernetes project tests releases—if it’s good enough for Kubernetes CI, it’s good enough for development.
minikube
Section titled “minikube”Installation
Section titled “Installation”# macOSbrew install minikube
# Linuxcurl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Verifyminikube versionBasic Usage
Section titled “Basic Usage”# Start clusterminikube start
# Start with specific resourcesminikube start --cpus 4 --memory 8192
# Start with specific driverminikube start --driver=docker
# Check statusminikube status
# Stop clusterminikube stop
# Delete clusterminikube delete
# SSH into nodeminikube sshAddons
Section titled “Addons”# List available addonsminikube addons list
# Enable addonsminikube addons enable ingressminikube addons enable metrics-serverminikube addons enable dashboard
# Access dashboardminikube dashboard
# Disable addonminikube addons disable dashboardAccessing Services
Section titled “Accessing Services”# Get service URLminikube service myapp --url
# Open service in browserminikube service myapp
# Tunnel for LoadBalancer servicesminikube tunnel
# Access via NodePortminikube ip # Get node IPMulti-Node minikube
Section titled “Multi-Node minikube”# Start with multiple nodesminikube start --nodes 3
# Add node to existing clusterminikube node add
# Delete specific nodeminikube node delete minikube-m02Profiles (Multiple Clusters)
Section titled “Profiles (Multiple Clusters)”# Create cluster with profileminikube start -p dev-clusterminikube start -p test-cluster
# List profilesminikube profile list
# Switch profileminikube profile dev-cluster
# Delete profileminikube delete -p test-cluster💡 Did You Know? minikube supports multiple “drivers” for virtualization: Docker, VirtualBox, Hyperkit, KVM, and even bare-metal. On macOS, the Docker driver is fastest because it doesn’t need a VM. On Linux, you can run minikube directly on the host with the “none” driver for maximum performance.
💡 Did You Know? minikube’s addons system is more extensive than most realize—there are 60+ addons available. Beyond the common ones (ingress, dashboard, metrics-server), you can enable Istio, Ambassador, registry, and even GPU support with single commands. It’s like having a curated marketplace of Kubernetes extensions, pre-configured to work together.
Docker Desktop Kubernetes
Section titled “Docker Desktop Kubernetes”Enabling Kubernetes
Section titled “Enabling Kubernetes”Docker Desktop → Settings → Kubernetes → Enable KubernetesFeatures
Section titled “Features”# No special commands - just workskubectl get nodes# NAME STATUS ROLES AGE VERSION# docker-desktop Ready control-plane 10m v1.28.2
# Reset if neededDocker Desktop → Settings → Kubernetes → Reset Kubernetes ClusterLimitations
Section titled “Limitations”- Single node only
- Can’t customize node configuration
- Tied to Docker Desktop lifecycle
- Limited resource control
When It’s Perfect
Section titled “When It’s Perfect”- You already have Docker Desktop
- Single-node is sufficient
- Don’t want to manage another tool
- Quick testing/development
Common Development Workflows
Section titled “Common Development Workflows”Local Registry with kind
Section titled “Local Registry with kind”# Create registry containerdocker run -d --restart=always -p 5000:5000 --name registry registry:2
# Create kind cluster with registrycat <<EOF | kind create cluster --config=-kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4containerdConfigPatches:- |- [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"] endpoint = ["http://registry:5000"]EOF
# Connect registry to kind networkdocker network connect kind registry
# Push to local registrydocker build -t localhost:5000/myapp:dev .docker push localhost:5000/myapp:dev
# Use in K8s# image: localhost:5000/myapp:devDevelopment Cluster Script
Section titled “Development Cluster Script”#!/bin/bash# dev-cluster.sh - Consistent dev environment
CLUSTER_NAME="dev"
# Delete existing if presentkind delete cluster --name $CLUSTER_NAME 2>/dev/null
# Create cluster with ingress supportcat <<EOF | kind create cluster --name $CLUSTER_NAME --config=-kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane extraPortMappings: - containerPort: 80 hostPort: 80 - containerPort: 443 hostPort: 443- role: workerEOF
# Install ingress controllerkubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# Wait for ingresskubectl wait --namespace ingress-nginx \ --for=condition=ready pod \ --selector=app.kubernetes.io/component=controller \ --timeout=90s
echo "Dev cluster ready!"Resource Management
Section titled “Resource Management”kind Resource Limits
Section titled “kind Resource Limits”kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane # Kind nodes are Docker containers, so limit via Docker extraMounts: - hostPath: /data/kind containerPath: /var/local-path-provisionerminikube Resources
Section titled “minikube Resources”# Start with specific resourcesminikube start --cpus 4 --memory 8g --disk-size 50g
# Check allocated resourcesminikube config view
# Set defaultsminikube config set cpus 4minikube config set memory 8192Common Mistakes
Section titled “Common Mistakes”| Mistake | Problem | Solution |
|---|---|---|
| Too many clusters | Eats all system resources | Delete unused clusters |
| No image loading | ImagePullBackOff errors | Use kind load docker-image |
| Ingress not working | Port mapping missing | Use config with extraPortMappings |
| Forgot which cluster | Commands hit wrong cluster | Use kubectl config current-context |
| Node not schedulable | Taints on control plane | Use worker nodes or tolerate taints |
| Storage not working | No StorageClass | Install local-path-provisioner |
War Story: The Missing Cluster
Section titled “War Story: The Missing Cluster”A developer spent 2 hours debugging why their pods weren’t starting. “ImagePullBackOff” everywhere. The cluster couldn’t pull from their local registry.
What went wrong:
- Built image locally:
docker build -t myapp:dev . - Deployed to kind:
kubectl apply -f deployment.yaml - kind couldn’t find image (it’s in host Docker, not kind’s containerd)
The fix:
# After building locally, load into kinddocker build -t myapp:dev .kind load docker-image myapp:dev
# OR use imagePullPolicy: Neverspec: containers: - name: myapp image: myapp:dev imagePullPolicy: NeverLesson: kind runs its own container runtime. Images must be explicitly loaded or come from a registry.
Question 1
Section titled “Question 1”When would you choose kind over minikube?
Show Answer
Choose kind when:
- Need multi-node cluster easily
- CI/CD testing (fast, ephemeral)
- Low resource usage is priority
- Don’t need addons
Choose minikube when:
- Need addons (dashboard, ingress, metrics)
- Want GPU support
- Need persistent storage
- Learning/tutorials (better docs)
kind is lighter and faster; minikube is more feature-rich.
Question 2
Section titled “Question 2”Why does kind load docker-image exist?
Show Answer
kind runs Kubernetes nodes as Docker containers. Each node has its own container runtime (containerd) separate from the host’s Docker.
When you docker build, the image is in host Docker.
When kind tries to run pods, it looks in the node’s containerd.
kind load docker-image:
- Exports image from host Docker
- Imports into each kind node’s containerd
Without this, you’d get ImagePullBackOff because the image doesn’t exist where Kubernetes is looking.
Question 3
Section titled “Question 3”How do you expose services with kind (no LoadBalancer)?
Show Answer
Three options:
1. Port mapping in cluster config:
nodes:- role: control-plane extraPortMappings: - containerPort: 80 hostPort: 802. NodePort services:
spec: type: NodePort ports: - port: 80 nodePort: 30080Access via localhost:30080
3. kubectl port-forward:
kubectl port-forward svc/myapp 8080:80Access via localhost:8080
For production-like ingress, use option 1 with nginx ingress controller.
Hands-On Exercise
Section titled “Hands-On Exercise”Objective
Section titled “Objective”Set up a local Kubernetes cluster with kind and deploy a sample application.
-
Install kind:
Terminal window brew install kind # or Linux method -
Create multi-node cluster:
Terminal window cat <<EOF | kind create cluster --config=-kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes:- role: control-plane- role: worker- role: workerEOF -
Verify nodes:
Terminal window kubectl get nodes -
Deploy sample app:
Terminal window kubectl create deployment nginx --image=nginxkubectl expose deployment nginx --port=80 -
Access via port-forward:
Terminal window kubectl port-forward svc/nginx 8080:80# Visit http://localhost:8080 -
Load local image:
Terminal window # Create simple imageecho 'FROM nginx:alpine' > Dockerfileecho 'RUN echo "Hello kind!" > /usr/share/nginx/html/index.html' >> Dockerfiledocker build -t my-nginx:dev .kind load docker-image my-nginx:devkubectl set image deployment/nginx nginx=my-nginx:dev -
Clean up:
Terminal window kind delete cluster
Success Criteria
Section titled “Success Criteria”- kind installed and working
- Multi-node cluster created
- Sample app deployed
- Can access app via port-forward
- Local image loaded and running
- Cluster deleted cleanly
Bonus Challenge
Section titled “Bonus Challenge”Add ingress support to your kind cluster and access nginx via hostname instead of port-forward.
Further Reading
Section titled “Further Reading”Toolkit Complete!
Section titled “Toolkit Complete!”Congratulations on completing the Developer Experience Toolkit! You’ve learned:
- k9s and CLI productivity tools
- Telepresence and Tilt for development workflows
- Local Kubernetes options
Continue exploring other toolkits or start applying these tools to your daily work.
“The best local cluster is the one that gets out of your way. Pick a tool, share the config, and focus on building.”