What Kubernetes is

Build a cluster and watch it keep an app running.

Beginner20 min · lesson 1 of 21
Lesson files
The scripts, test data and local test servers this lesson uses, exactly as they ran on the lab machine (2 files, 1 KB): whatis.tar.gz. The lab VM shares no folders with your computer, so fetch them inside the VM: cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/k8s-fund/whatis.tar.gz && tar -xzf whatis.tar.gz, which creates ~/lab/whatis/. SHA-256: 20230590edbf22f0001ca4644c8281c891b27d82e6ac293fa230751926af7523

With Docker you can start a container on one machine. If that machine reboots, the container is gone until someone starts it again. If you need three copies, you start three and keep track of them yourself. And when a new version comes out, you stop the old containers and start new ones, hoping nobody notices the gap. That works for a laptop. It stops working once an app has to keep running while machines fail and people go home.

Kubernetes takes that bookkeeping off you. You tell it what you want, for example "three copies of this web server", and it keeps checking whether that is true. When a copy disappears, it starts another. When a machine dies, it starts the copies somewhere else. You stop giving orders and start describing a result. Everything else in this course builds on that one idea.

What you need

A Linux machine or virtual machine with Docker Engine and about 4 GB of free memory. The Ubuntu VM from the Docker course works well. Every lesson in this course ran on Ubuntu 26.04 with Docker Engine 29.9.3, and the install script below is for Linux. Docker Desktop on macOS or Windows can run kind too, but you would install the tools with your package manager, and a few later steps that reach a node's IP address directly only work from inside Linux.

You also need two tools. kind ("Kubernetes in Docker") builds a cluster out of Docker containers, so you can run a real multi-node cluster on one machine. kubectl is the command-line client you use to talk to any Kubernetes cluster, including big ones in the cloud. This script installs both and refuses to continue if a download does not match the checksum its project publishes:

install-tools.sh
#!/usr/bin/env bash
# Installs kind and kubectl into /usr/local/bin, each checked against the sha256 its project publishes.
# Run it on the Linux machine or VM where Docker runs: ./install-tools.sh
set -euo pipefail
KIND=v0.33.0
KUBECTL=$(curl --retry 3 --retry-all-errors -fsSL https://dl.k8s.io/release/stable.txt) # the newest stable Kubernetes release
case $(uname -m) in
x86_64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported CPU: $(uname -m)"; exit 1 ;;
esac
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
cd "$tmp"
curl --retry 3 --retry-all-errors -fsSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND/kind-linux-$arch"
curl --retry 3 --retry-all-errors -fsSLo kind.sha256 "https://github.com/kubernetes-sigs/kind/releases/download/$KIND/kind-linux-$arch.sha256sum"
echo "$(cut -d' ' -f1 kind.sha256) kind" | sha256sum --check
curl --retry 3 --retry-all-errors -fsSLo kubectl "https://dl.k8s.io/release/$KUBECTL/bin/linux/$arch/kubectl"
curl --retry 3 --retry-all-errors -fsSLo kubectl.sha256 "https://dl.k8s.io/release/$KUBECTL/bin/linux/$arch/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -m 0755 kind kubectl /usr/local/bin/
kind version
kubectl version --client
ubuntu@secopslog-k8s:~/lab/whatis · Kubernetes 1.37
$ ./install-tools.sh
kind: OK kubectl: OK kind v0.33.0 go1.26.7 linux/arm64 Client Version: v1.37.2 Kustomize Version: v5.8.1
$ docker version --format "Docker Engine {{.Server.Version}}"
Docker Engine 29.9.3

The two OK lines are the checksum checks passing. kubectl is v1.37.2, the newest stable Kubernetes release when these labs ran.

Build a cluster

A cluster is a group of machines, called nodes, that Kubernetes treats as one place to run things. This file asks kind for three nodes: one control-plane node that makes decisions and two workers that run your apps.

kind.yaml
# One control-plane node and two workers, each a Docker container on this machine.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
ubuntu@secopslog-k8s:~/lab/whatis · Kubernetes 1.37
$ kind create cluster --name lab --config kind.yaml
Creating cluster "lab" ... • Ensuring node image (kindest/node:v1.37.0) 🖼️ ... ✓ Ensuring node image (kindest/node:v1.37.0) 🖼️ • Preparing nodes 📦 📦 📦 ... ✓ Preparing nodes 📦 📦 📦 • Writing configuration 📜 ... ✓ Writing configuration 📜 • Starting control-plane 🕹️ ... ✓ Starting control-plane 🕹️ • Installing CNI 🔌 ... ✓ Installing CNI 🔌 • Installing StorageClass 💾 ... ✓ Installing StorageClass 💾 • Joining worker nodes 🚜 ... ✓ Joining worker nodes 🚜 Set kubectl context to "kind-lab" You can now use your cluster with: kubectl cluster-info --context kind-lab Have a nice day! 👋
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION lab-control-plane NotReady control-plane 23s v1.37.0 lab-worker NotReady <none> 5s v1.37.0 lab-worker2 NotReady <none> 5s v1.37.0
$ kubectl wait --for=condition=Ready nodes --all --timeout=120s && kubectl get nodes
node/lab-control-plane condition met node/lab-worker condition met node/lab-worker2 condition met NAME STATUS ROLES AGE VERSION lab-control-plane Ready control-plane 58s v1.37.0 lab-worker Ready <none> 40s v1.37.0 lab-worker2 Ready <none> 40s v1.37.0

kind printed a few steps, then pointed kubectl at the new cluster (the context kind-lab). Asked straight away, all three nodes were NotReady: they existed, but their networking was still starting. Half a minute later all three were Ready. The VERSION column shows Kubernetes v1.37.0, the version kind v0.33.0 builds by default. kubectl can be a little newer than the cluster, so v1.37.2 talks to it without trouble.

Each node is just a container:

ubuntu@secopslog-k8s:~/lab/whatis · Kubernetes 1.37
$ docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES IMAGE STATUS lab-control-plane kindest/node:v1.37.0 Up About a minute lab-worker2 kindest/node:v1.37.0 Up About a minute lab-worker kindest/node:v1.37.0 Up About a minute

On a real cluster each node would be its own server or cloud VM. Here they share one machine, which is fine for learning, since Kubernetes behaves the same way.

Describe what you want

Now ask for three copies of nginx. A Deployment is the object that says "keep this many copies of this container running". Each running copy lives in a Pod, the smallest thing Kubernetes runs. Both get their own lessons soon.

ubuntu@secopslog-k8s:~/lab/whatis · Kubernetes 1.37
$ kubectl create deployment web --image=nginx:1.30.6-alpine --replicas=3
deployment.apps/web created
$ kubectl rollout status deployment/web
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
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES web-56d6d5bd78-85ldt 1/1 Running 0 2s 10.244.2.2 lab-worker <none> <none> web-56d6d5bd78-8zxxr 1/1 Running 0 2s 10.244.1.2 lab-worker2 <none> <none> web-56d6d5bd78-x2v75 1/1 Running 0 2s 10.244.2.3 lab-worker <none> <none>

Kubernetes chose the nodes itself. Two Pods landed on one worker and one on the other, and the control-plane node got none, because kind keeps apps off it. Each Pod got its own IP address. You did not pick any of that.

Break it and watch

Delete one Pod, the kind of thing a crash or a failed machine does to you:

ubuntu@secopslog-k8s:~/lab/whatis · Kubernetes 1.37
$ kubectl delete pod "$(kubectl get pods -l app=web -o name | head -1 | cut -d/ -f2)"
pod "web-56d6d5bd78-85ldt" deleted from default namespace
$ kubectl rollout status deployment/web && kubectl get pods
deployment "web" successfully rolled out NAME READY STATUS RESTARTS AGE web-56d6d5bd78-8zxxr 1/1 Running 0 6s web-56d6d5bd78-lkjv8 1/1 Running 0 3s web-56d6d5bd78-x2v75 1/1 Running 0 6s
$ kubectl get deployment web
NAME READY UP-TO-DATE AVAILABLE AGE web 3/3 3 3 6s

The deleted Pod's name is gone from the list. A new Pod, a few seconds younger than the other two, has taken its place. Nobody told Kubernetes to start it. The Deployment still says three, the cluster saw two, and it closed the gap. That loop of compare, then fix, runs all the time, and it is called reconciliation.

This is also why you rarely touch Pods directly. Delete a Pod that a Deployment owns and you get a new one. To really remove the app, you delete the Deployment.

Hands-on

1. Delete all three Pods at once: kubectl delete pods -l app=web. The -l picks Pods by their label; lesson 7, Labels, explains how.

2. Wait for the Deployment to catch up with kubectl rollout status deployment/web, then list the Pods with kubectl get pods. How many are there, and how old?

3. Remove the app properly: kubectl delete deployment web.

4. Wait for its Pods to go with kubectl wait --for=delete pod -l app=web --timeout=90s, then run kubectl get pods again.

5. Check which kind clusters exist: kind get clusters.

What you should see: in step 2 the rollout status counts back up from 0 of 3, and the list shows three Pods with new names, all a second or two old. In step 4 each Pod reports condition met as it goes, and kubectl get pods says No resources found in default namespace. Step 5 prints lab.

Every later lesson uses this lab cluster, so keep it running. If you need the memory back, kind delete cluster --name lab removes it, and kind create cluster --name lab --config kind.yaml builds a fresh one in about a minute.

Remember

You describe the state you want and Kubernetes keeps making it true. A Deployment holds the "how many", Pods are the running copies, and deleting a Pod only gets you a replacement.

Quick check
01A Deployment asks for three Pods. You delete one of them. What happens next?
Incorrect — Deleting a Pod does not change the Deployment. It still asks for three.
Incorrect — No command is needed. The lab replaced the Pod on its own within seconds.
Correct — The cluster compares what exists with what was asked for, sees one missing, and starts another.
Incorrect — The replacement is a new Pod. Its name, and usually its IP, are different.
02In the lab, what is each kind "node"?
Correct — docker ps listed one container per node. On a real cluster each node would be a server or VM.
Incorrect — kind starts no VMs. The nodes showed up in docker ps.
Incorrect — Nodes run Pods, not the other way round.
Incorrect — kubectl is only a client. It talks to the cluster and runs nothing itself.
03kubectl is v1.37.2 and the cluster is v1.37.0. What does that mean for the labs?
Incorrect — The lab connected and worked with exactly these versions.
Incorrect — kubectl never changes the cluster's version.
Incorrect — Every command in the lab, including create and delete, worked.
Correct — kubectl is supported within one minor version of the cluster either way, and these two share a minor version.

Related