Kubernetes basics
About this lesson
Kubernetes runs containers across a cluster of machines and keeps them running. You write down the state you want in a manifest, such as three copies of a web server, and the control plane works to make it true. Follow one Deployment from a YAML file to running Pods, see a Service spread traffic over them, scale it with a one-character edit, and watch the cluster heal itself when a node dies.
A cluster of machines
Kubernetes runs containers across a cluster: a group of machines called nodes. A control plane manages them. You normally do not say "start this here"; you say what you want, and Kubernetes keeps the real state matching it.
cluster = control plane + worker nodes control plane API server the front door etcd the store of state scheduler picks a node per Pod controllers close the gap nodes: Node 1, Node 2, Node 3
Read the lesson step by step
A cluster of machines
Kubernetes runs containers across a cluster: a group of machines called nodes. A control plane manages them. You normally do not say "start this here"; you say what you want, and Kubernetes keeps the real state matching it.
cluster = control plane + worker nodes control plane API server the front door etcd the store of state scheduler picks a node per Pod controllers close the gap nodes: Node 1, Node 2, Node 3Write the desired state
A manifest is a YAML file (a plain-text settings format) describing an object. This Deployment asks for three replicas (copies) of a Pod running the container image nginx:1.27. It states the goal, not the steps to reach it: that is declarative.
web.yaml kind: Deployment replicas: 3 ← how many image: nginx:1.27 ← what to run declarative: say WHAT, not HOWApply it
kubectl, the Kubernetes command-line tool, runs apply -f web.yaml to send the manifest to the API server, the front door of the control plane. It checks the object and saves it in etcd, the cluster's database. Desired state is now 3 Pods; running is 0.
$ kubectl apply -f web.yaml deployment.apps/web created kubectl → API server → etcd desired 3 · running 0Create and place Pods
A controller sees 3 wanted, 0 existing, and creates 3 Pods. A Pod is the smallest unit Kubernetes runs: one or more containers sharing a network address. The scheduler then assigns each new Pod to a node.
controllers: want 3, have 0 → create 3 Pods (Deployment → ReplicaSet → Pods) scheduler: Pod with no node? pick one web-7d4b9c8f5-x2k9p → Node 1 web-7d4b9c8f5-m4tqz → Node 2 web-7d4b9c8f5-b8wns → Node 3 status: PendingThe kubelet starts them
Each node runs an agent called the kubelet. It sees a Pod assigned to its node, pulls the image nginx:1.27 and asks the container runtime (the program that runs containers) to start it. The Pods turn Running: 3 of 3.
kubelet on each node: a Pod for me? pull the image nginx:1.27 start the container $ kubectl get deployment web NAME READY UP-TO-DATE AVAILABLE AGE web 3/3 3 3 10sOne address for all
Pods come and go, and each has its own address. A Service gives them one stable name and IP. It finds the Pods by their label app: web, and each request goes to one of them.
Service "web" → selector app: web stable cluster IP + DNS name request 1 → a web Pod request 2 → a web Pod request 3 → a web Pod (kube-proxy picks one, at random by default)Scale by editing
More visitors? Change replicas: 3 to replicas: 4 and apply again. Nothing else changes. The controller sees 4 wanted, 3 existing, creates one more Pod, and the scheduler places it.
- replicas: 3 + replicas: 4 $ kubectl apply -f web.yaml deployment.apps/web configured want 4, have 3 → create 1 desired 4 · running 4A node fails
Node 3 loses power. Its kubelet stops reporting, the node is marked not ready, and after a timeout its Pod is evicted. Desired is still 4, but only 3 are running. Nobody has to notice.
Node 3: NotReady (no heartbeats) after 5 min (default) its Pods are evicted desired 4 · running 3 gap = 1It heals itself
The controller sees 4 wanted, 3 running, and creates a new Pod. The scheduler skips the dead node and places it on Node 2. Running is 4 again.
controllers: want 4, have 3 → create 1 scheduler: Node 3 not ready → Node 2 desired 4 · running 4 no one was pagedThe control loop
This is the whole idea. You declare the desired state in a file. Controllers loop forever: watch the actual state, compare, act to close the gap. A thermostat works the same way.
loop forever: observe what is running? compare desired vs actual act create or delete Pods thermostat: set 21 °C, heater on/off
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01Which control plane component picks the node a new Pod runs on?
The kube-scheduler looks for Pods that are not yet bound to a node and assigns each one to a suitable node. The kubelet on that node then starts it.
02What does replicas: 3 in a Deployment manifest mean?
replicas is part of the desired state. The controllers keep creating or deleting Pods until exactly that many matching Pods exist.
03Why put a Service in front of the Pods?
A Service selects Pods by label (here app: web) and gives clients one stable address, however often the Pods behind it are replaced.
04A node dies and its Pod is lost, so 3 Pods run but 4 are desired. What happens?
This is the control loop: observe the actual state, compare it with the desired state, act to close the gap. By default the Pod is evicted 5 minutes after the node becomes unreachable.
05What does it mean that Kubernetes manifests are declarative?
You state what you want (four replicas of nginx:1.27), not how to get there. To change it you edit the file and apply it again.
Glossary
- Cluster
- A set of machines run by Kubernetes: a control plane that makes decisions and worker nodes that run the containers.
- Node
- One machine (physical or virtual) in the cluster that runs Pods. Each node runs a kubelet.
- Pod
- The smallest unit Kubernetes runs: one or more containers that share a network address and storage.
- Deployment
- An object that keeps a set number of identical Pods running and updates them in a controlled way.
- Manifest
- A file, usually YAML, that describes a Kubernetes object and its desired state.
- Control plane
- The parts that manage the cluster: the API server, etcd, the scheduler and the controllers.
- Controller
- A loop that watches the cluster, compares the actual state with the desired state and acts to close the gap.
- Service
- A stable name and IP address in front of a set of Pods, chosen by label, that spreads traffic over them.
Notes and sources
- Strictly, a Deployment creates a ReplicaSet and the ReplicaSet controller creates the Pods; the figure shows both controllers as one block. Both run inside kube-controller-manager.
- A dead node is not handled at once. Kubernetes adds a default toleration of 300 seconds for node.kubernetes.io/not-ready and unreachable, so Pods stay bound to the node for 5 minutes before they are evicted and replaced.
- With kube-proxy in its default iptables mode, each new connection goes to a backend Pod chosen at random, not strictly in turn. The figure sends one request to each Pod to keep it simple.
- Real clusters often run the control plane on several machines for safety, and a node usually holds many Pods. Three small nodes keep the picture readable.
- The card is a complete apps/v1 Deployment in YAML flow style; kubectl apply -f web.yaml accepts it as is. The selector must match the template labels (app: web).
- Kubernetes docs: Kubernetes Components
- Kubernetes docs: Controllers
- Kubernetes docs: Deployments
- Kubernetes docs: ReplicaSet
- Kubernetes docs: Pods
- Kubernetes docs: Service
- Kubernetes docs: Virtual IPs and Service Proxies
- Kubernetes docs: Taints and Tolerations (taint-based evictions)
- Kubernetes docs: Declarative Management of Kubernetes Objects Using Configuration Files
Quiz Unlocks after the last step.