Skip to main content
Kubernetes coreLesson 1 of 13

Build a Lab Cluster on Your Laptop

Every "Try it yourself" section on this site needs a cluster. Build one on your laptop with kind (Kubernetes in Docker), where each Kubernetes node is just a container. It is free, takes a minute, and you can throw it away at any time.

Cluster—
Current context—
Nodes—
App Pod—
Container runtime on your laptop (e.g. Docker)Youterminalkubectltalks to the API~/.kube/configcontext kind-labcontrol-planenode containerworkernode containerworker2node containerPodmy-app:devLocal imagemy-app:devRegistrydocker.ioBrowserlocalhost:8080Commands
RequestWatchAppears in a later step

What you will learn

  • What kind creates: a container per node, running kubelet and the control plane
  • How kubeconfig contexts decide which cluster kubectl talks to
  • A multi-node config for practicing drains and scheduling
  • Why a locally built image gives ImagePullBackOff, and kind load
  • Reaching the app with port-forward, NodePort and extraPortMappings

kind and minikube side by side​

Both tools give you a real cluster on one machine. kind runs nodes as containers. minikube can run its node as a container (docker driver) or as a VM.

Taskkindminikube
Createkind create cluster --name labminikube start -p lab
Multi-node--config lab.yaml with a nodes listminikube start -p lab --nodes 3
kubectl contextkind-lablab (the profile name)
Load a local imagekind load docker-image my-app:dev --name labminikube -p lab image load my-app:dev
Reach an appkubectl port-forward, or NodePort + extraPortMappingskubectl port-forward, or minikube service my-app
Deletekind delete cluster --name labminikube delete -p lab
SymptomLikely causeFix
ErrImagePull / ImagePullBackOff for your own imageImage is only on your laptop, or the tag is :latestkind load docker-image, then use a fixed tag or imagePullPolicy: IfNotPresent
Pods Pending, nodes NotReady, OOMKilledNot enough memory or CPU for the runtimeGive the Docker VM more resources, or use fewer nodes
Commands hit the wrong clusterCurrent context points elsewherekubectl config use-context kind-lab
kind create fails because a port is in useAnother process uses a host port from extraPortMappingsFree the port or pick another hostPort
localhost:8080 refuses connectionsport-forward was stopped, or the Service port is wrongRun it again and check kubectl get svc

Try it yourself​

# 0. Check the tools
docker info >/dev/null && echo "runtime ok"
kind version
kubectl version --client

# 1. A 3-node cluster: 1 control-plane, 2 workers, host port 30080 -> NodePort 30080
cat > lab.yaml <<'EOF'
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 30080
- role: worker
- role: worker
EOF
kind create cluster --name lab --config lab.yaml
docker ps --format '{{.Names}}' # lab-control-plane, lab-worker, lab-worker2
kubectl config current-context # kind-lab
kubectl get nodes -o wide

# 2. Run an app and reach it
kubectl create deployment web --image=nginx:1.27 --replicas=2
kubectl expose deployment web --port=80
kubectl port-forward svc/web 8080:80 # open http://localhost:8080, Ctrl+C to stop

# 3. Your own image: build, load, run (use a fixed tag, not :latest)
# docker build -t my-app:dev .
# kind load docker-image my-app:dev --name lab
# kubectl create deployment my-app --image=my-app:dev

# 4. Practice a drain
kubectl drain lab-worker --ignore-daemonsets
kubectl get pods -o wide # Pods moved to lab-worker2
kubectl uncordon lab-worker

# 5. Clean up
kind delete cluster --name lab

Check yourself

  1. You built my-app:dev with docker build and deployed it to kind. The Pod shows ImagePullBackOff. Why?
  2. You loaded my-app:latest with kind load, but the Pod still tries to pull from the registry. What is the fix?
  3. You have a work cluster and a kind cluster in the same kubeconfig. What decides which one kubectl delete affects?

Further reading: kind Quick Start · minikube start · Install kubectl · Organizing cluster access with kubeconfig · Draining Nodes and Upgrading the Cluster · How an Image Is Built and Run