Section 1: How Kubernetes thinks
Desired state and the control loop
The single most important idea in Kubernetes is desired state. You do not tell Kubernetes "start three copies of this container". You tell it "there should be three copies of this container", and Kubernetes keeps it true.
If a container crashes, Kubernetes starts another. If a machine dies, the copies on it are recreated elsewhere. If you change the desired state to five copies, two more appear. This is done by controllers, small loops that repeatedly compare the desired state with the actual state and act on the difference.
The parts of a cluster
Control plane components make decisions:
- API server: the front door. Every command, from you or from inside the cluster, goes through it.
- etcd: a key value store that holds the cluster's state.
- Scheduler: decides which node a new Pod should run on.
- Controller manager: runs the built in controllers, such as the one that manages Deployments.
Nodes are the machines that run your workloads. Each node runs:
- kubelet: an agent that starts and watches containers assigned to its node.
- A container runtime, usually containerd.
- kube-proxy or an equivalent from the network plugin, which implements Service networking.
Everything is an object
Pods, Deployments, Services, ConfigMaps: all are objects stored in the API with a spec (what you want) and a status (what is true now). You create and change them by sending YAML or JSON to the API server, usually with kubectl.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
# ...
Every manifest has the same four top level parts: apiVersion, kind, metadata and spec.
Declarative, not imperative
You can run imperative commands such as kubectl create deployment, and they are handy for experiments. For real work, keep manifests in Git and apply them with kubectl apply -f. The files become the record of what should be running, reviewed like code. Tools for GitOps, such as Argo CD and Flux, build on exactly this idea.
In the next lesson we create a cluster and send it our first objects.