Kubernetes Labs · Lab 1 of 9
Your First Kubernetes Cluster: Architecture, Deployments and Self-Healing
Create a three-node cluster on your computer with kind, see every control-plane and node component running, deploy an app, scale it, delete a pod and watch Kubernetes replace it, then roll out a new version and roll it back.
- Environment
- Kubernetes
- Level
- Beginner
- Time
- About 45 min
- Cost
- Free
You will build
A local Kubernetes cluster with one control-plane node and two workers, a Deployment of three pods, and a clear
picture of which component does what when you run kubectl apply.
Before you start
Docker running on your computer (
docker version)kind 0.33 or newer (
kind version)kubectl 1.37 or newer (
kubectl version --client)
kind (Kubernetes in Docker) runs each Kubernetes node as a Docker container, so you get a real multi-node cluster on a laptop. It is the same Kubernetes that EKS, GKE and AKS run: the API, objects and kubectl commands you learn here work unchanged in the cloud labs later.
The parts of a cluster
A cluster has two halves. The control plane decides what should run; the nodes run it.
- kube-apiserver is the front door. kubectl, the other components and every controller talk only to it, over HTTPS. It authenticates you, checks what you may do (RBAC), runs admission checks and stores objects.
- etcd is the database where the API server keeps every object: the desired state you asked for and the actual state the nodes report.
- kube-scheduler watches for pods without a node and picks one, based on free CPU and memory and your rules.
- kube-controller-manager runs the control loops: the Deployment controller creates ReplicaSets, the ReplicaSet controller creates pods, the Node controller notices dead nodes, and so on.
- cloud-controller-manager (only on cloud clusters) creates cloud load balancers, routes and disks.
On every node:
- kubelet asks the API server which pods belong on its node, starts them and reports their status.
- containerd is the container runtime that actually pulls images and runs containers.
- kube-proxy programs the node's network rules so a Service IP reaches the right pods.
- The CNI plugin (kindnet here) gives every pod its own IP address across nodes.
- CoreDNS runs as ordinary pods and answers DNS names such as
web.demo.svc.cluster.local.
Every output below was captured from a real run on kind 0.33 with Kubernetes 1.37. Pod names, IP addresses, ages and cluster ports are generated, so yours will differ; everything else should match.
Project structure
first-cluster/ ├── kind-config.yaml # 1 control-plane + 2 worker nodes, port mappings for lab 2 └── web.yaml # namespace demo + Deployment web (3 replicas)
Steps
-
1Describe the cluster
This file asks kind for three nodes. The port mappings are not used yet: in the next lab they let traffic from
localhost:8080andlocalhost:8081reach the cluster.kind-config.yaml # A local cluster: 1 control-plane node and 2 workers, each a Docker container. kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 name: lab-k8s-local nodes: - role: control-plane extraPortMappings: # Lab 2: traffic from your computer into the cluster (Gateway and NodePort). - containerPort: 30080 hostPort: 8080 - containerPort: 30081 hostPort: 8081 - role: worker - role: worker -
2Create the cluster
kind pulls the node image, starts three containers, installs Kubernetes and points kubectl at the new cluster.
Run kind create cluster --config kind-config.yamlExpected output
Creating cluster "lab-k8s-local" ... ✓ Ensuring node image (kindest/node:v1.37.0) 🖼️ ✓ Preparing nodes 📦 📦 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 ✓ Joining worker nodes 🚜 Set kubectl context to "kind-lab-k8s-local" You can now use your cluster with: kubectl cluster-info --context kind-lab-k8s-local
Check:docker psshows three containers namedlab-k8s-local-….Hint
The first run downloads the node image (about 400 MB). If it fails with a port error, something else uses 8080 or 8081: change
hostPortin the file. -
3Look at the nodes
Run kubectl cluster-info kubectl get nodes -o wideExpected output
Kubernetes control plane is running at https://127.0.0.1:35253 CoreDNS is running at https://127.0.0.1:35253/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME lab-k8s-local-control-plane Ready control-plane 30s v1.37.0 172.21.0.4 <none> Debian GNU/Linux 13 (trixie) 7.0.0-42-generic (amd64) containerd://2.3.4 lab-k8s-local-worker Ready <none> 16s v1.37.0 172.21.0.2 <none> Debian GNU/Linux 13 (trixie) 7.0.0-42-generic (amd64) containerd://2.3.4 lab-k8s-local-worker2 Ready <none> 16s v1.37.0 172.21.0.3 <none> Debian GNU/Linux 13 (trixie) 7.0.0-42-generic (amd64) containerd://2.3.4
Check:All three nodes are
Ready. -
4Find every component of the architecture
The control plane runs as pods in the
kube-systemnamespace. On the control-plane node you can see etcd, kube-apiserver, kube-controller-manager and kube-scheduler. Every node runs kube-proxy and kindnet (the CNI plugin), and CoreDNS runs two replicas. kind has no cloud-controller-manager because there is no cloud.Run kubectl get pods -n kube-system -o wideExpected output
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES coredns-559f6c778d-2mn8j 1/1 Running 0 19s 10.244.0.2 lab-k8s-local-control-plane <none> <none> coredns-559f6c778d-2z5dv 1/1 Running 0 20s 10.244.0.4 lab-k8s-local-control-plane <none> <none> etcd-lab-k8s-local-control-plane 1/1 Running 0 29s 172.21.0.4 lab-k8s-local-control-plane <none> <none> kindnet-785bj 1/1 Running 0 16s 172.21.0.2 lab-k8s-local-worker <none> <none> kindnet-qcgg9 1/1 Running 0 16s 172.21.0.3 lab-k8s-local-worker2 <none> <none> kindnet-sq7r7 1/1 Running 0 20s 172.21.0.4 lab-k8s-local-control-plane <none> <none> kube-apiserver-lab-k8s-local-control-plane 1/1 Running 0 28s 172.21.0.4 lab-k8s-local-control-plane <none> <none> kube-controller-manager-lab-k8s-local-control-plane 1/1 Running 0 28s 172.21.0.4 lab-k8s-local-control-plane <none> <none> kube-proxy-bvqrp 1/1 Running 0 16s 172.21.0.3 lab-k8s-local-worker2 <none> <none> kube-proxy-xgl76 1/1 Running 0 20s 172.21.0.4 lab-k8s-local-control-plane <none> <none> kube-proxy-xl4vx 1/1 Running 0 16s 172.21.0.2 lab-k8s-local-worker <none> <none> kube-scheduler-lab-k8s-local-control-plane 1/1 Running 0 29s 172.21.0.4 lab-k8s-local-control-plane <none> <none>
Check:You can point at each box of the architecture diagram in this list.
-
5Write a Deployment
A Deployment says "keep three copies of this pod running". The
selectorand the podlabelsmust match: that is how the Deployment finds its pods.requeststell the scheduler how much CPU and memory to reserve; the memorylimitis the most the container may use.web.yaml apiVersion: v1 kind: Namespace metadata: name: demo --- apiVersion: apps/v1 kind: Deployment metadata: name: web namespace: demo labels: app: web spec: replicas: 3 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: whoami image: traefik/whoami:v1.11.0 ports: - containerPort: 80 resources: requests: cpu: 50m memory: 32Mi limits: memory: 64Mi -
6Apply it and follow the chain of objects
One
kubectl applysets off a chain of controllers. You asked for a Deployment; the Deployment controller created a ReplicaSet; the ReplicaSet controller created three Pods; the scheduler spread them over the two workers; each kubelet started its containers.What happens after kubectl apply: from a YAML file to running containers Run kubectl apply -f web.yaml kubectl -n demo rollout status deployment/web kubectl -n demo get deployments,replicasets,pods -o wideExpected output
namespace/demo created deployment.apps/web created Waiting for deployment "web" rollout to finish: 0 of 3 updated replicas are available... Waiting for deployment "web" rollout to finish: 1 of 3 updated replicas are available... Waiting for deployment "web" rollout to finish: 2 of 3 updated replicas are available... deployment "web" successfully rolled out NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR deployment.apps/web 3/3 3 3 2s whoami traefik/whoami:v1.11.0 app=web NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR replicaset.apps/web-c47fdc9f6 3 3 3 2s whoami traefik/whoami:v1.11.0 app=web,pod-template-hash=c47fdc9f6 NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/web-c47fdc9f6-77qsx 1/1 Running 0 2s 10.244.2.2 lab-k8s-local-worker2 <none> <none> pod/web-c47fdc9f6-d6886 1/1 Running 0 2s 10.244.1.2 lab-k8s-local-worker <none> <none> pod/web-c47fdc9f6-gcttj 1/1 Running 0 2s 10.244.2.3 lab-k8s-local-worker2 <none> <none>
Check:The pod names start with the ReplicaSet name, and the ReplicaSet name starts with the Deployment name.
-
7Scale out
Changing
replicasis all it takes; the ReplicaSet creates the missing pods.Run kubectl -n demo scale deployment/web --replicas=5 kubectl -n demo get pods -o wideExpected output
deployment.apps/web scaled NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES web-c47fdc9f6-77qsx 1/1 Running 0 11s 10.244.2.2 lab-k8s-local-worker2 <none> <none> web-c47fdc9f6-d6886 1/1 Running 0 11s 10.244.1.2 lab-k8s-local-worker <none> <none> web-c47fdc9f6-gcttj 1/1 Running 0 11s 10.244.2.3 lab-k8s-local-worker2 <none> <none> web-c47fdc9f6-lwn5t 1/1 Running 0 4s 10.244.1.3 lab-k8s-local-worker <none> <none> web-c47fdc9f6-nzbxl 1/1 Running 0 4s 10.244.2.4 lab-k8s-local-worker2 <none> <none>
Hint
kubectl scaleis handy for experiments; in production you changereplicasin Git (or let an autoscaler do it, lab 4). -
8Delete a pod and watch it come back
Pods are disposable. Delete one (use a name from your own list) and the ReplicaSet notices that only four exist and creates a fifth within seconds. The events show the whole sequence.
Run kubectl -n demo delete pod web-c47fdc9f6-77qsx kubectl -n demo get pods kubectl -n demo get events --sort-by=.lastTimestamp | tail -6Expected output
pod "web-c47fdc9f6-77qsx" deleted from demo namespace NAME READY STATUS RESTARTS AGE web-c47fdc9f6-d6886 1/1 Running 0 14s web-c47fdc9f6-fjsnd 1/1 Running 0 3s web-c47fdc9f6-gcttj 1/1 Running 0 14s web-c47fdc9f6-lwn5t 1/1 Running 0 7s web-c47fdc9f6-nzbxl 1/1 Running 0 7s 3s Normal Created pod/web-c47fdc9f6-fjsnd Container created 3s Normal Started pod/web-c47fdc9f6-fjsnd Container started 3s Normal Scheduled pod/web-c47fdc9f6-fjsnd Successfully assigned demo/web-c47fdc9f6-fjsnd to lab-k8s-local-worker2 3s Normal SuccessfulCreate replicaset/web-c47fdc9f6 Created pod: web-c47fdc9f6-fjsnd 3s Normal Pulled pod/web-c47fdc9f6-fjsnd Container image "traefik/whoami:v1.11.0" already present on machine and can be accessed by the pod 3s Normal Killing pod/web-c47fdc9f6-77qsx Stopping container whoami
Check:Still five pods; one is only a few seconds old.
-
9Roll out a new version
Changing the pod template (here the image) makes the Deployment create a new ReplicaSet and move pods over a few at a time, so the app never goes down. The old ReplicaSet is kept with zero pods: that is your rollback point. The
change-causeannotation shows up in the rollout history.Deployment owns ReplicaSets, ReplicaSets own Pods; a rollout swaps which ReplicaSet has the pods Run kubectl -n demo set image deployment/web whoami=traefik/whoami:v1.12.0 kubectl -n demo annotate deployment/web kubernetes.io/change-cause="upgrade whoami to v1.12.0" kubectl -n demo rollout status deployment/web kubectl -n demo get replicasets kubectl -n demo rollout history deployment/webExpected output
deployment.apps/web image updated deployment.apps/web annotated Waiting for deployment "web" rollout to finish: 3 out of 5 new replicas have been updated... ... Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "web" rollout to finish: 4 of 5 updated replicas are available... deployment "web" successfully rolled out NAME DESIRED CURRENT READY AGE web-7d46fc8569 5 5 5 2s web-c47fdc9f6 0 0 0 22s deployment.apps/web REVISION CHANGE-CAUSE 1 <none> 2 upgrade whoami to v1.12.0
-
10Roll back
rollout undoscales the previous ReplicaSet back up. Read the warning: the cluster now differs from yourweb.yaml, and the nextkubectl apply -f web.yamlwill put its own image back. In production you roll back by reverting the change in Git and applying again, so files and cluster never disagree.Run kubectl -n demo rollout undo deployment/web kubectl -n demo rollout status deployment/web kubectl -n demo get deployment web -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'Expected output
Warning: resource deployments/web was previously managed with 'kubectl apply'. Rolling back will not update the kubectl.kubernetes.io/last-applied-configuration annotation, which may cause unexpected behavior on future 'kubectl apply' operations. Consider using 'kubectl apply' with your previous configuration file instead. deployment.apps/web rolled back Waiting for deployment "web" rollout to finish: 2 out of 5 new replicas have been updated... ... deployment "web" successfully rolled out traefik/whoami:v1.11.0
-
11Talk to a pod
port-forwardopens a tunnel from your computer to one pod through the API server. It is a debugging tool: it always hits the same pod, as the repeated hostname shows. Lab 2 uses Services to spread real traffic. Leave it running, use a second terminal forcurl, then press Ctrl+C.Run kubectl -n demo port-forward deployment/web 8080:80 # in a second terminal for i in 1 2 3; do curl -s localhost:8080 | grep Hostname; doneExpected output
Hostname: web-c47fdc9f6-299c6 Hostname: web-c47fdc9f6-299c6 Hostname: web-c47fdc9f6-299c6
-
12Clean up the app
Deleting a namespace deletes everything in it. Keep the cluster: the next labs use it.
Run kubectl delete namespace demoExpected output
namespace "demo" deleted
In production
A kind cluster is perfect for learning and for testing manifests in CI, but everything that makes it convenient is something a production cluster must do differently.
What changes
| In this lab | In production |
|---|---|
| One control-plane node in a Docker container | A managed control plane (EKS, GKE, AKS) with replicated API servers and etcd across zones |
| Two workers on your laptop | Node pools across three availability zones, sized by autoscaling |
kubectl apply, scale and rollout undo by hand |
Manifests in Git, applied by CI or a GitOps controller (lab 9); rollbacks are Git reverts |
| Your admin kubeconfig | Individual identities via SSO, RBAC per team, no shared admin credentials |
| Images from Docker Hub by tag | Images from your own registry, pinned by digest, scanned before deploy |
| No probes on the Deployment | Readiness, liveness and startup probes on every container (lab 4) |
| Pods may land on the same node | Topology spread constraints or anti-affinity so one node or zone can't take all replicas |
The idea that carries over
Everything in Kubernetes is a control loop: you declare the desired state, controllers keep making the actual state match it. You saw it twice: a deleted pod came back, and a rollout replaced pods one by one. Production practices build on this: GitOps makes Git the desired state, autoscalers change replicas, and you stop running imperative commands against production.
Production checklist
- Use a managed control plane, or at least three control-plane nodes with etcd backups
- Run at least two replicas of every user-facing workload, spread across zones
- Set CPU and memory requests (and a memory limit) on every container
- Pin image versions; never deploy
:latest - Keep every manifest in Git and change production only through reviewed pull requests
- Record why each rollout happened (commit messages,
change-cause, deployment tooling) - Give people their own identities and least-privilege RBAC instead of the admin kubeconfig
Learn the concepts
- Cluster Architecture · Kubernetes Tutorial
- kubectl Essentials · Kubernetes Tutorial
- Pods · Kubernetes Tutorial
- Deployments · Kubernetes Tutorial
- Rolling Updates and Rollbacks · Kubernetes Tutorial
- Kubernetes in Production · Course
Preparing for the CKA or CKS exam? Practice tests and mock exams →