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—
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.
| Task | kind | minikube |
|---|---|---|
| Create | kind create cluster --name lab | minikube start -p lab |
| Multi-node | --config lab.yaml with a nodes list | minikube start -p lab --nodes 3 |
| kubectl context | kind-lab | lab (the profile name) |
| Load a local image | kind load docker-image my-app:dev --name lab | minikube -p lab image load my-app:dev |
| Reach an app | kubectl port-forward, or NodePort + extraPortMappings | kubectl port-forward, or minikube service my-app |
| Delete | kind delete cluster --name lab | minikube delete -p lab |
| Symptom | Likely cause | Fix |
|---|---|---|
ErrImagePull / ImagePullBackOff for your own image | Image is only on your laptop, or the tag is :latest | kind load docker-image, then use a fixed tag or imagePullPolicy: IfNotPresent |
Pods Pending, nodes NotReady, OOMKilled | Not enough memory or CPU for the runtime | Give the Docker VM more resources, or use fewer nodes |
| Commands hit the wrong cluster | Current context points elsewhere | kubectl config use-context kind-lab |
kind create fails because a port is in use | Another process uses a host port from extraPortMappings | Free the port or pick another hostPort |
localhost:8080 refuses connections | port-forward was stopped, or the Service port is wrong | Run 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
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