Learn Labs
Foundations

kind & Setup

A multi-node cluster in Docker, the platform bootstrap, and the lab runner

Everything in this module lives in kubernetes/ in the repository. kind (Kubernetes in Docker) runs each cluster node as a Docker container that contains a kubelet, a container runtime, and (on the control plane) the control-plane components. It's how Kubernetes itself is tested, and it gives you a real multi-node cluster on a laptop.

Tools

brew install kind helm kubernetes-cli
kind version            # kind v0.33.0
kubectl version --client  # v1.37.1
helm version --short    # v4.3.0

The minimal cluster

kind create cluster --config cluster.yaml --wait 120s   # one node; --wait: until it's usable
kubectl get nodes
kind delete cluster --name minimal

The production-shaped cluster

kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4name: labnodes:- role: control-planeimage: kindest/node:v1.37.0extraPortMappings:host ports -> NodePorts on this node- { containerPort: 30080, hostPort: 8180 }the Gateway- { containerPort: 30081, hostPort: 8281 }kube-state-metrics- role: workerlabels: { topology.kubernetes.io/zone: zone-a }- role: workerlabels: { topology.kubernetes.io/zone: zone-b }- role: workerlabels: { topology.kubernetes.io/zone: zone-c }
HTTPS APIwatch / statuscontrol planeAPI server, etcd, scheduler, controllerslab-workerzone-a: kubelet, kube-proxylab-worker2zone-blab-worker3zone-ckubectl, labseach node is a Docker container (kind); zones are node labels

The zone labels are what cloud providers put on nodes in different availability zones. Spreading, disruption budgets and volume placement read them, so the labs behave like a three-zone cluster.

kind create cluster --config cluster_prod.yaml --wait 120s
kubectl get nodes -L topology.kubernetes.io/zone
NAME                STATUS   ROLES           VERSION   ZONE
lab-control-plane   Ready    control-plane   v1.37.0
lab-worker          Ready    <none>          v1.37.0   zone-a
lab-worker2         Ready    <none>          v1.37.0   zone-b
lab-worker3         Ready    <none>          v1.37.0   zone-c

The platform: scripts/bootstrap.sh

A bare cluster can run pods, but production clusters always add a few platform components. The script installs them with pinned versions, then the app:

Gateway API CRDs v1.6.3the Gateway / HTTPRoute resource typesNGINX Gateway Fabric 2.7.2an implementation: provisions NGINX per Gateway (Helm)metrics-server 0.9.0CPU/memory per pod: kubectl top, the HPAkube-state-metrics 2.20.0object state as Prometheus metricslearning/k8s-lab-app:v1built locally, loaded into every node (kind load docker-image)kubectl apply -k manifests/namespace, Redis, the web app, policies, Gateway
./scripts/bootstrap.sh
curl http://localhost:8180/api/whoami
{"pod": "web-5c6cf9586b-l5q7x", "node": "lab-worker2", "version": "v1"}

The lab runner

./scripts/lab.sh rollouts.py

lab.sh writes an admin kubeconfig that points at the API server by its container name (kind get kubeconfig --internal), builds the labs image (Python, the Kubernetes client, kubectl), and runs it on kind's Docker network with the Docker socket mounted, so node_failure.py can stop a node.

The labs container is outside the pod network: pod IPs (10.244.x.x) only route between nodes. The first version of probes.py tried to call a pod directly and timed out. Labs now reach pods through a toolbox Deployment in a labs namespace, the way you'd debug from inside a real cluster.

Lab

  1. Create the minimal cluster, then docker ps: what is a "node"?
  2. Create the lab cluster and run bootstrap.sh. Run kubectl get pods -A -o wide and sort the pods into "control plane", "platform" and "app".
  3. docker exec -it lab-worker crictl ps: the containers on one node, as its kubelet sees them.

On this page