Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Infrastructure

How does Kubernetes work?

Kubernetes is not a command runner. It keeps comparing what you asked for with what exists, and fixes the gap. Here is the loop, piece by piece.

Derpx0630 Oct · 4 min read
Contents
Who restarts my app at 3 a.m.?What are desired state and actual state?What is the control loop?What are the pieces?What is a Pod, and why do I rarely touch it?What keeps the count at three?How do I find a Pod that keeps changing?Can I try it?What should I learn next?Sources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
Who restarts my app at 3 a.m.?What are desired state and actual state?What is the control loop?What are the pieces?What is a Pod, and why do I rarely touch it?What keeps the count at three?How do I find a Pod that keeps changing?Can I try it?What should I learn next?Sources

You tell Kubernetes, "I want three copies of my app running." Then you stop one on purpose, and a new one appears. Nobody pressed a button.

Here is the key idea. Kubernetes does not just run commands. It keeps comparing what you asked for with what is actually happening, and fixes any gap, again and again. Once you see that, the rest is just names.

Who restarts my app at 3 a.m.?

Say your app runs in a container (a sealed box holding your app and everything it needs). One container on one machine is easy. Now run 50 of them across 10 machines, and one crashes at 3 a.m.

The official docs say it plainly: "if a container goes down, another container needs to start." Kubernetes (Greek for "helmsman or pilot") is the system that does that job for you.

So how does it know something went wrong? It keeps two notes.

What are desired state and actual state?

The desired state is what you want. The actual state is what exists right now. Kubernetes keeps both written down and works to close the difference.

What I asked forDesired state: 3 copies of my app
→
What exists right nowActual state: 2 copies (one crashed)
The gap is the to-do list.

You write the desired state in a file (the spec). Kubernetes keeps the current state next to it. You never say "start a copy." You say "I want 3," and it works out the rest.

You describe the goal, not the steps. Next, who does the fixing?

What is the control loop?

The docs use a room thermostat as the example. You set 24 degrees (desired). The room is 28 (actual). The thermostat switches the cooling on until they match, then switches it off. A controller is like that thermostat, for your cluster.

Look at desired state
Look at actual state
Spot the gap
Make a small fix
↺ repeat
A non-terminating loop that regulates the state of a system (the docs' words).

It never finishes. The docs even say your cluster "potentially never reaches a stable state," and that is fine as long as the controllers keep running.

So what are these controllers, and where do they live?

What are the pieces?

A cluster is a group of machines. Each machine is a node. One part is the "brain" (the control plane), and the rest do the work.

Pods: your containers
Nodes: machines running them with a kubelet
Control plane: API server, etcd, scheduler, controllers
Three floors of the building.
PieceWhat the docs say it does
API serverThe front end of the control plane. Everything talks to it.
etcdA consistent, highly-available key value store holding all cluster data.
SchedulerWatches for new Pods with no node and picks one for them.
Controller managerRuns the controller processes.
KubeletAgent on each node. Makes sure the containers in its Pods are running and healthy.

Think of etcd as the one notebook everyone agrees is the truth. Only the API server writes to it. The other parts ask the API server.

Now what are the "Pods" in the diagram?

What is a Pod, and why do I rarely touch it?

A Pod is "the smallest deployable unit" in Kubernetes: one or more containers sharing storage and network. Usually it is one container in one Pod.

Pods are disposable. The docs say you will "rarely create individual Pods directly" because Pods are "relatively ephemeral, disposable entities." If a node fails, the Pod is gone. So you put something in charge of Pods.

What keeps the count at three?

A Deployment is the thermostat for Pods. You ask for "3 copies of nginx." It makes a ReplicaSet, which makes the Pods. When you update the app, it slowly swaps old Pods for new ones.

1Deployment
2ReplicaSet
33 Pods
Each layer has one simple job.

Now let's follow one Deployment all the way down. Click Next and watch which piece lights up.

You
API server + etcd
Controller
Scheduler
Kubelet

You send the Deployment to the API server, and it is saved in etcd

Step 1 of 5
Every piece talks through the API server. That is why the docs call it the front end.

Look at the last step. Nothing starts over. The same loop just runs again.

How do I find a Pod that keeps changing?

Pods come and go, and each new one gets a new IP address (its network address). So how does anyone find your app? Imagine a shop that changes its street address every week.

A Service is the fix. The docs call it a way to expose an app running as one or more Pods. It picks Pods by their labels (name tags), so the set can change and the Service still finds them. Each node also runs kube-proxy (the docs say some network plugins do this job themselves) to make Services work on the network.

Can I try it?

You need a cluster. minikube or kind gives you one on a laptop. These commands are from the official Deployment docs:

Bash
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
kubectl get deployments
kubectl scale deployment/nginx-deployment --replicas=10
kubectl get pods

Now delete one Pod with kubectl delete pod <name> and run kubectl get pods again. A new one shows up. That is the loop doing its job.

What should I learn next?

  • Write a Pod and a Deployment YAML by hand.
  • Read about Services and how they pick Pods with a selector.
  • Try kubectl describe pod and read the events. They show what the scheduler and kubelet did.
  • Later: StatefulSets (for apps that need to remember things), and writing your own controller.
Key takeaways
  • Kubernetes keeps comparing desired state with actual state and fixes the gap, over and over.
  • That comparing-and-fixing is a control loop, like a thermostat. Controllers are the loops.
  • The API server is the front door, etcd stores the truth, the scheduler picks a node, the kubelet runs the Pod.
  • Pods die, so you use a Deployment to keep the count and a Service to keep a stable address.

Sources

  • Kubernetes Overview
  • Cluster Architecture
  • Controllers
  • Deployments
  • Pods
  • Service
  • kubelet reference
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Infrastructure · 5 minHow does Docker work? (A container is not a tiny computer)Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)