- #kubernetes
- #k8s
- #devops
Kubernetes 101: Running Containers at Scale
Clusters, nodes, pods, Deployments and Services in plain words, and what really happens when you run kubectl apply. Then run, scale, break and roll back an app on a local cluster.
Akshit Bansal20 min readTutorial 3
the manager for your containerson this page
In one minute
Kubernetes- Kubernetes (K8s for short: K, then 8 letters, then s) runs containers across a group of machines.
- You write down what you want ("3 copies of my web app"), and it keeps that true, forever.
- If a container crashes or a machine dies, it starts a replacement by itself.
- It does not build images. Docker (or a similar tool) builds them; Kubernetes runs them.
Words you need
Cluster
A group of machines that Kubernetes manages as one big computer.
Like a whole apartment society
Node
One machine in the cluster, real or a VM. Your containers run on nodes.
Like one building in the society
Control plane
The brain of the cluster. It stores what you want and decides where things run. It does not run your app.
Like the society office
Pod
The smallest thing Kubernetes runs: a wrapper around one container (sometimes a few) with one IP address. Pods are disposable.
Like one tenant; when they leave, a new one moves in
Replica
One identical copy of a pod. Three replicas = three copies of your app sharing the work.
Like three cashiers doing the same job
Deployment
Your instruction 'keep N replicas of this pod running', plus safe updates to a new version.
Like a standing order: always keep 3 flats rented
Service
One fixed name and address in front of a changing group of pods. Callers use the Service, never a pod.
Like the society's reception phone number
Desired state
What you said you want, written down. Kubernetes keeps comparing reality to it and fixes differences.
Like a thermostat set to 24°C
Manifest (YAML)
A text file in YAML format that describes the desired state.
Like the order form
kubectl
The command-line tool you use to talk to a cluster. Say it 'kube-control' or 'kube-cuddle'; both are common.
Like the phone to the society office
Label
A key=value sticker on an object, like app=web. Services and Deployments find pods by their labels.
Like a name tag at an event
Namespace
A folder inside the cluster that groups objects, often one per team or environment.
Like one wing of the building
Why Kubernetes exists
Docker runs containers on one machine. Real apps need more: many copies, many machines, and nobody awake at 3 a.m. to restart things.
| Job | By hand with docker run + SSH | With Kubernetes |
|---|---|---|
| A server dies | You notice, SSH elsewhere, restart everything | Pods are rescheduled on healthy nodes automatically |
| Traffic spike | Start more copies by hand, edit the load balancer | Change a number, or let the autoscaler do it |
| New version | Stop, pull, start on every server; downtime | Rolling update, one pod at a time; rollback in one command |
| Where does it run | A spreadsheet of IPs | The scheduler picks a node with room |
What it gives you, from the official overview:
Self-healing
Restarts crashed containers, replaces pods on dead nodes, and stops sending traffic to pods that fail their health checks.
Scaling
Change one number to run more or fewer copies, or let an autoscaler do it from CPU usage.
Load balancing
A Service gives pods one name and spreads requests across the healthy ones.
Rollouts and rollbacks
Moves to a new version a few pods at a time, and back again with one command.
Bin packing
You say how much CPU and memory each container needs; it fits them onto nodes efficiently.
Config and secrets
Keeps settings and passwords outside your images, so one image works everywhere.
The cluster, piece by piece
Control plane (the brain)
Worker node 1
Worker node 2
| Component | Its job | Lives on |
|---|---|---|
| kube-apiserver | The front door. Every command and every component talks to the cluster through it | Control plane |
| etcd | A small database holding the whole desired state of the cluster | Control plane |
| kube-scheduler | Finds pods with no node yet and picks a suitable node for each | Control plane |
| kube-controller-manager | Runs the controllers: loops that fix differences between wanted and actual | Control plane |
| kubelet | The node's agent: makes sure the pods assigned to this node are running | Every node |
| kube-proxy | Sets up network rules so Service addresses reach the right pods | Every node |
| Container runtime | Actually runs containers, for example containerd | Every node |
What happens when you run kubectl apply
- 01
kubectl sends your YAML
to the API server
- 02
Saved in etcd
this is now the desired state
- 03
Deployment controller acts
creates a ReplicaSet, which creates 3 pods
- 04
Scheduler picks nodes
each pod gets a node with room
- 05
kubelet on that node starts it
asks containerd to pull the image and run it
- 06
Status reported back
kubectl get pods shows Running
Desired state and the reconcile loop
You never say "start 3 pods". You say "there should be 3 pods", and controllers keep making it true.
Break it yourself: change replicas, delete pods, take nodes down, and read the log.
Control planein sync
wanted
node-1Ready
- web-1Running
node-2Ready
- web-2Running
node-3Ready
- web-3Running
A first manifest, explained
# Annotated example, not the walkthrough fileapiVersion: apps/v1kind: Deployment # "keep N copies running"metadata: name: webspec: replicas: 3 # how many copies selector: matchLabels: app: web # manage pods with this label template: # what each pod looks like metadata: labels: app: web spec: containers: - name: web image: hits:1.0 # the image Docker built ports: - containerPort: 3000---apiVersion: v1kind: Service # one stable name in front of the podsmetadata: name: webspec: selector: app: web # send traffic to pods labelled app=web ports: - port: 80 # the Service's port targetPort: 3000 # the container's portThe objects that matter
| Object | What it is | Society analogy |
|---|---|---|
| Pod | Smallest unit: 1+ containers sharing an IP. Disposable, gets a new IP when replaced | A tenant |
| Deployment | Keeps N identical pods running, does rolling updates and rollbacks | "Always keep 3 flats rented" |
| Service | One stable name and IP in front of changing pods, picked by label | The society's reception number |
| ConfigMap / Secret | Settings / passwords outside the image. Secrets are only base64, not encrypted | The notice board / the locked drawer |
| Namespace | A folder for objects, per team or environment | A wing of the building |
| PVC | A request for storage that outlives pods | A storeroom you rent |
| HPA | Adds or removes pods based on CPU (needs requests + metrics-server) | More guards at festival time |
| Gateway API | Routes outside HTTP traffic in. Replaces Ingress for new work (ingress-nginx retired March 2026) | The main gate |
Pods labelled app=web
| Service type | Reachable from | Use for |
|---|---|---|
| ClusterIP (default) | Inside the cluster only | Service-to-service calls |
| NodePort | A port on every node | Quick tests, bare-metal setups |
| LoadBalancer | A real cloud load balancer | Public traffic on a cloud (costs money) |
| Probe / setting | Question it answers | If it fails |
|---|---|---|
| readinessProbe | Can this pod take traffic now? | Removed from the Service, keeps running |
| livenessProbe | Is the process stuck? | Container restarted |
| startupProbe | Has a slow app finished booting? | Others wait; restarted if it never boots |
| requests | How much does it need? (scheduler uses this) | Pod stays Pending if no node has room |
| limits | Hard ceiling | CPU throttled; memory: OOMKilled |
Quick check: Your /health checks the database and you use it as the liveness probe. The database blips for 20 s. What happens?
More objects you will meet
Job / CronJob
kind: CronJobRuns to completion: migrations, backups, reports. CronJob runs it on a schedule.
StatefulSet
web-0, web-1, web-2Pods with stable names and their own volumes. For databases you cannot buy managed.
DaemonSet
one per nodeOne pod on every node: log shippers, monitoring agents, network plugins.
RBAC
Role + RoleBindingWho may do which actions on which objects. Give apps the least they need.
NetworkPolicy
podSelector + ingressA firewall between pods. By default every pod can reach every pod.
Helm / Kustomize
helm install / kubectl apply -kPackage and template YAML. Helm for third-party apps, Kustomize for per-environment patches.
Rolling, blue-green and canary
Built into every Deployment (maxSurge 1, maxUnavailable 0 here). What you do in the walkthrough.
Servicesends to every ready pod
- v1ready25%
- v1ready25%
- v1ready25%
- v1ready25%
v1 ready v2 ready starting% = share of requests
Step 1/6:
Rolling update
Built into every Deployment (maxSurge 1, maxUnavailable 0 here). What you do in the walkthrough.
- [v1 v1 v1 v1] v2 traffic 0%: Four v1 pods serve everything.
- [v1 v1 v1 v1 v2-starting] v2 traffic 0%: One extra v2 pod starts. It gets no traffic until its readiness probe passes.
- [v1 v1 v1 v2] v2 traffic 25%: v2 is ready, so one v1 pod is removed. A quarter of requests now hit v2.
- [v1 v1 v2 v2] v2 traffic 50%: Repeat: surge one, wait for ready, remove one.
- [v1 v2 v2 v2] v2 traffic 75%: Both versions serve at once the whole time, so they must be compatible.
- [v2 v2 v2 v2] v2 traffic 100%: Done. kubectl rollout undo walks the same steps backwards.
Blue-green
Two full Deployments; the Service selector (or a Gateway route) flips between them.
- [v1 v1 v1 v1] v2 traffic 0%: Blue (v1) is live.
- [v1 v1 v1 v1 v2-starting v2-starting v2-starting v2-starting] v2 traffic 0%: Green (v2) starts in full beside it. You test it privately. Costs double for a while.
- [v1-idle v1-idle v1-idle v1-idle v2 v2 v2 v2] v2 traffic 100%: One switch moves all traffic. Rollback is the same switch back: instant.
- [v2 v2 v2 v2] v2 traffic 100%: After a soak period, blue is deleted.
Canary
Send a small share to v2 and watch errors and latency. Done with Gateway API route weights or a tool such as Argo Rollouts.
- [v1 v1 v1 v1] v2 traffic 0%: v1 serves everything.
- [v1 v1 v1 v1 v2] v2 traffic 5%: One canary pod gets 5% of requests. Watch the dashboards.
- [v1 v1 v1 v2 v2] v2 traffic 25%: Metrics look healthy, so the weight goes up.
- [v1 v1 v2 v2 v2] v2 traffic 50%: If errors spike at any step, the weight goes back to 0 and only a few users noticed.
- [v2 v2 v2 v2] v2 traffic 100%: Promoted.
Reading pod status
Most problems show up first in the STATUS column of kubectl get pods. Pick one:
kubectl cheat sheet
| Command | What it does |
|---|---|
| kubectl get pods (-o wide) | List pods (-o wide: with node and IP) |
| kubectl describe pod POD | Everything about one pod; read Events at the bottom |
| kubectl logs POD (--previous) | The app's output (--previous: from the last crash) |
| kubectl apply -f FILE | Create or update objects from YAML |
| kubectl delete -f FILE | Delete the objects in that YAML |
| kubectl exec -it POD -- sh | Shell inside a pod's container |
| kubectl port-forward svc/web 8080:80 | Reach a Service from your laptop |
| kubectl scale deployment web --replicas=5 | Change the number of copies |
| kubectl rollout status / undo deployment/web | Watch an update / go back to the previous version |
| kubectl get events --sort-by=.lastTimestamp | What just happened in the cluster |
When not to use Kubernetes
- One app or a few on one server: Compose is simpler.
- Nobody on the team will own upgrades, access rules and monitoring.
- A managed container service does the job: Cloud Run, AWS ECS/Fargate, Azure Container Apps.
- Small, steady traffic: autoscaling buys you nothing.
Your Kubernetes roadmap
Topics from the roadmap.sh Kubernetes roadmap (opens in a new tab). Ticks stay in your browser.
Kubernetes roadmap
0/16Learn now
Learn next
DIY walkthrough
You will run the hits app from Docker 101 on a real three-node cluster made with kind (Kubernetes in Docker), then scale it, kill pods, update it, break it and roll it back.
Before you start
You need the hits folder and the hits:1.0 image from the Docker 101 walkthrough, and Docker running. Check:
docker image ls hitsYou should see hits with tag 1.0. Run every command below from inside the hits folder.
Install kind and kubectl
winget install Kubernetes.kindwinget install -e --id Kubernetes.kubectlClose and reopen PowerShell so the new commands are on your PATH.
brew install kind kubectlThis downloads the kind binary: the amd64 build (the page has an arm64 variant) and the version number in the address may be newer by the time you read this, so check the kind quick start (opens in a new tab).
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.33.0/kind-linux-amd64chmod +x ./kindsudo mv ./kind /usr/local/bin/kindFor kubectl, follow the official Linux guide (opens in a new tab). sudo snap install kubectl --classic is a shortcut if you have snap.
Check the tools and make a folder
kind versionkubectl version --clientmkdir k8sYou should see
Both commands print a version, and an empty k8s folder now exists inside hits.
Build the cluster and deploy
kind (Kubernetes in Docker) builds a real cluster whose nodes are Docker containers. That is why it is perfect for a laptop, and why, on Windows and macOS, the whole cluster ends up as containers inside Docker Desktop's hidden VM.
kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes: - role: control-plane - role: worker - role: workerThe Redis file runs one Redis and gives it a Service named redis. It has no persistent volume, which is a deliberate shortcut and you will see its cost soon.
apiVersion: apps/v1kind: Deploymentmetadata: name: redisspec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:7-alpine ports: - containerPort: 6379 resources: requests: cpu: 50m memory: 32Mi limits: memory: 128Mi---apiVersion: v1kind: Servicemetadata: name: redisspec: selector: app: redis ports: - port: 6379 targetPort: 6379The web file has four things: a ConfigMap with the Redis address, a Deployment with three copies, probes and resource settings, and a Service that gives them one name. The rolling update settings mean "never remove a working pod before its replacement is ready".
apiVersion: v1kind: ConfigMapmetadata: name: hits-configdata: REDIS_URL: redis://redis:6379---apiVersion: apps/v1kind: Deploymentmetadata: name: webspec: replicas: 3 selector: matchLabels: app: web strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 template: metadata: labels: app: web spec: containers: - name: web image: hits:1.0 imagePullPolicy: IfNotPresent envFrom: - configMapRef: name: hits-config ports: - containerPort: 3000 readinessProbe: httpGet: path: /healthz port: 3000 periodSeconds: 3 livenessProbe: httpGet: path: /healthz port: 3000 initialDelaySeconds: 10 periodSeconds: 10 resources: requests: cpu: 50m memory: 64Mi limits: memory: 128Mi---apiVersion: v1kind: Servicemetadata: name: webspec: selector: app: web ports: - port: 80 targetPort: 3000Create the cluster
The first run downloads a large node image, so be patient.
kind create cluster --name hits --config k8s/kind.yamlkubectl get nodesYou should see
kind prints a few progress lines and ends with a message that you can now use your cluster. kubectl get nodes lists three nodes, all Ready (this can take a minute).Get your image into the cluster
The cluster's nodes cannot see the images on your Docker. Normally they would pull from a registry. For a local image, load it into the nodes.
kind load docker-image hits:1.0 --name hitsYou should see
kind prints that it loaded the image onto each node.Apply the desired state
kubectl apply -f k8s/redis.yaml -f k8s/web.yamlkubectl get pods --watchPress Ctrl+C once everything is Running, then:
kubectl rollout status deployment/webkubectl get podsYou should see
After a short wait, rollout status says the deployment was successfully rolled out, and kubectl get pods shows three web pods and one redis pod, all Running and 1/1 Ready.Open a door to the Service
port-forwardis a temporary tunnel from your laptop to the Service. It is for debugging, not for production. Run it in one terminal and leave it running, and curl from another.kubectl port-forward service/web 8081:80curl http://localhost:8081Notice the "served by" name is always the same pod: the tunnel picked one pod when it started. To see the Service spreading load, ask from inside the cluster instead.
kubectl exec deploy/web -- wget -T 5 -qO- http://webkubectl exec deploy/web -- wget -T 5 -qO- http://webkubectl exec deploy/web -- wget -T 5 -qO- http://webYou should see
The port-forward command stays running and prints Forwarding from 127.0.0.1:8081. In a second terminal the curl prints hits with a version of 1.0.Scale it
kubectl scale deployment/web --replicas=5kubectl get podskubectl scale deployment/web --replicas=3You should see
Five web pods are listed and become Ready within a few seconds. Scaling back to three terminates two.Kill a pod and watch it come back
Pick any pod name from the list, replace
POD_NAMEwith it, and delete it. This is the reconcile loop, live.kubectl get pods -l app=webkubectl delete pod POD_NAMEkubectl get pods -l app=webYou should see
The pod you deleted goes Terminating, and a new pod with a different suffix appears right away. The count stays at three.Feel the missing volume
Redis here has no persistent storage, so its data lived and died with its pod. Real data needs a PVC (or a managed database).
kubectl delete pod -l app=rediskubectl rollout status deployment/rediskubectl exec deploy/web -- wget -T 5 -qO- http://webYou should see
After the Redis pod is replaced, the counter starts again at 1. The pod's disk went with it.Roll out version 2.0
Build a second image with a different version baked in, load it, and tell the Deployment to use it.
docker build -t hits:2.0 --build-arg VERSION=2.0 .kind load docker-image hits:2.0 --name hitskubectl set image deployment/web web=hits:2.0kubectl rollout status deployment/webkubectl exec deploy/web -- wget -T 5 -qO- http://webIf your port-forward from before dropped, that is normal: the pod it was attached to was replaced. Start it again if you want it.
You should see
Old pods are replaced gradually. rollout status ends with a success message. Calling the Service now prints version: 2.0.Break it on purpose
Point the Deployment at a tag that does not exist. Because we set
maxUnavailable: 0, Kubernetes refuses to remove a working pod until the new one is ready, so your app stays up.kubectl set image deployment/web web=hits:9.9kubectl get pods -l app=webkubectl get events --sort-by=.lastTimestampRead the output top to bottom. Then ask for details of the broken pod (replace
BAD_PODwith its name). Look at the Events section at the bottom.kubectl describe pod BAD_PODYou should see
One new pod is stuck in ErrImagePull and then ImagePullBackOff, while the three version 2.0 pods keep serving traffic. The events end with a line like 'Back-off pulling image hits:9.9'.Roll back
kubectl rollout undo deployment/webkubectl rollout status deployment/webkubectl exec deploy/web -- wget -T 5 -qO- http://webYou should see
rollout undo reports the rollback and rollout status ends with a success message. The broken pod disappears, and the Service answers with version: 2.0 again.
Clean up
Stop any port-forward terminal with Ctrl+C first.
Delete the cluster
kind delete cluster --name hitskind get clustersYou should see
kind get clusters prints no clusters.Delete the images
The kind node image is large. List it, then remove it by the image ID in the first column. Then delete the
hitsfolder.docker image rm hits:1.0 hits:2.0docker image ls kindest/nodeYou should see
docker images no longer lists hits.
Troubleshooting
Check the pod's status first: see Reading pod status.
Running on Kubernetes
kubectl exec ... wget times out straight after a rollout
Cause
Fix
Run the same command again. If every attempt fails, check that the Service has healthy pods behind it.
kubectl get endpointslices -l kubernetes.io/service-name=webkubectl get pods -l app=webThe connection to the server localhost:8080 was refused - did you specify the right host or port?
Cause
Fix
docker pskind get clusterskubectl config get-contextskubectl config use-context kind-hitsIf the cluster is missing, recreate it with the kind create cluster step.
web pod status: ErrImagePull, then ImagePullBackOff
Cause
Fix
Read the exact reason in the Events at the bottom of describe. Then fix the tag or load the image.
kubectl describe pod POD_NAMEkind load docker-image hits:1.0 --name hitsIf kind load itself errors, save the image to a file and load that instead.
docker save hits:1.0 -o hits.tarkind load image-archive hits.tar --name hitsErrImageNeverPull
Cause
Fix
Load the image into the cluster, or switch the policy back to IfNotPresent in the YAML and apply again.
kind load docker-image hits:1.0 --name hitskubectl apply -f k8s/web.yamlCrashLoopBackOff
Cause
Fix
Read the logs of the crashed attempt, not the new empty one.
kubectl logs POD_NAME --previouskubectl describe pod POD_NAMEPending, and the event says: 0/3 nodes are available: 3 Insufficient memory
Cause
Fix
Check what the event says exactly, then lower the requests in the YAML or give Docker more memory (Docker Desktop settings, Resources). Also look for a taint or label mismatch if the event says so.
kubectl describe pod POD_NAMEkubectl describe nodesReason: OOMKilled, Exit Code: 137
Cause
Fix
Find it in describe, then raise the memory limit or fix the memory use.
kubectl describe pod POD_NAMEEdit limits.memory in k8s/web.yaml and apply it again.
Readiness probe failed: HTTP probe failed with statuscode: 503
Cause
Fix
Check the path, the port and the app's logs. The probe has to hit a URL that really exists.
kubectl describe pod POD_NAMEkubectl logs POD_NAMEIf the failure says connection refused during start-up, raise initialDelaySeconds or add a startup probe.
error: lost connection to pod
Cause
Fix
Run the command again. It picks a pod that exists now.
kubectl port-forward service/web 8081:80bind: address already in use
Cause
Fix
Stop the old one with Ctrl+C, or choose another local port such as 8082:80.
A debug routine for any pod that is not running
Whatever the status says, work through the same five checks in order. Most problems show up in the first two.
- 01
get pods
What is the status?
- 02
describe
Read Events at the bottom
- 03
logs
What did the app say?
- 04
logs --previous
What did the last crash say?
- 05
exec
Look inside and test
kubectl get podskubectl describe pod POD_NAMEkubectl logs POD_NAMEkubectl logs POD_NAME --previouskubectl exec -it POD_NAME -- shNext steps and sources
- Add a PersistentVolumeClaim to Redis so the counter survives a pod deletion.
- Install metrics-server and try a HorizontalPodAutoscaler on
web. - Replace the port-forward with a Gateway API (opens in a new tab) route.
- Compare all three: Docker vs Kubernetes vs VM.
- Official docs: kubernetes.io/docs/concepts/overview (opens in a new tab) and cluster components (opens in a new tab); kind quick start (opens in a new tab)
- roadmap.sh Kubernetes roadmap (opens in a new tab)
- Video this was planned around: Kubernetes vs Docker (opens in a new tab) by NextWork