Containers and orchestration
The control plane and the reconciliation loop
The parts that run a Kubernetes cluster, and the loop that compares what you asked for with what is running and closes the gap. Includes the path a deployment takes to become running pods.
Kubernetes is a set of programs that watch objects you store in one API. Each program compares what the object asks for with what is actually running, and acts to close the gap. This page covers the parts and the loop that makes the cluster heal itself.
Concept
A reconciliation loop is a controller that repeatedly checks desired state (what you wrote to the API) against observed state (what is running). When they differ, it takes an action. A deleted pod is replaced because the loop sees one fewer pod than it should.
The big idea
You never tell a node to start a container. You write an object, and the controllers do the rest. If something breaks later, the same loops notice and repair it.
The loop only heals what it can fix. A pod stuck in Pending or CrashLoopBackOff is still in the desired state, but the loop cannot make it run. Those states are your signal to look closer.
The parts
| Component | Runs on | Job |
|---|---|---|
| API server | Control plane | The only front door. Authenticates, validates and stores objects. |
| etcd | Control plane | Strongly consistent store for cluster state. If it is unhealthy, the cluster cannot safely change. |
| Scheduler | Control plane | Picks a node for each pod with no node yet, and binds it. |
| Controller manager | Control plane | Runs built-in loops such as Deployment, ReplicaSet and Node controllers. |
| kubelet | Each worker node | Starts and stops containers for pods bound to its node. Reports status. |
| Container runtime | Each worker node | Runs the container image, usually containerd. |
Walking through a deployment
Say you apply a Deployment with replicas: 3. Here is what happens:
- The API server authenticates you, checks permissions, and stores the Deployment in etcd.
- The Deployment controller creates a ReplicaSet with a desired count of 3.
- The ReplicaSet controller creates three Pod objects. None has a node yet, so each is
Pending. - The scheduler finds a node with room for each pod and writes the node name into the pod.
- The kubelet on that node pulls the image and starts the container.
- The pod reports
Ready, and traffic can flow to it.
If step 5 fails, the pod stays in a visible state such as ImagePullBackOff or CrashLoopBackOff. The API is the source of truth. kubectl get only reads it.
Managed services (EKS, GKE, AKS) run this control plane for you. You still own the worker nodes and everything you deploy.
Common mistakes
- Thinking
kubectlis the cluster. It is a client. The state lives in the API and etcd. - Ignoring intermediate states.
Pending,ContainerCreatingandImagePullBackOffeach point to a different layer. - Running etcd yourself without a reason. Its health gates every change to the cluster.
Check yourself
- You delete one pod owned by a ReplicaSet with 3 replicas. What happens? The ReplicaSet controller sees 2 pods, creates a replacement, and the scheduler places it.
- Why does a new pod sit in
Pending? It has no node name yet, so the scheduler has not found a node that fits it.
Key takeaways
- Kubernetes is a set of reconciliation loops over desired state in the API.
- Controllers create objects, the scheduler places pods, and kubelets start containers.
- A visible intermediate state tells you which step is stuck.
Further learning
Next, learn which workload object fits your app in pods and workload objects. The official overview is the reference.
Kubernetes concepts (official docs)The Concepts section helps you learn about the parts of the Kubernetes system and the abstractions Kubernetes uses to represent your cluster, and helps you obtain a deeper understanding of how Kubernetes works.Kubernetes
Related
Kubernetes core concepts
The control loop at the heart of Kubernetes, the objects you use every day, and how a request reaches a pod. Start here for the map of Kubernetes pages.
Consensus and Raft
How a cluster agrees on one value or one log despite crashes and partitions, how Raft works, and where etcd, ZooKeeper and consensus-backed databases fit.
Containers from the inside
Namespaces, cgroups and layered images - what a container really is, how images are built and shipped, and how to write small, fast, secure Dockerfiles.