Desired state and reconciliation
See what Kubernetes does when you ask for three Pods and one disappears.
What you will understand
- Identify desired state and observed state in a Deployment.
- Follow the controller loop that creates a replacement.
- Explain why a cluster can keep trying without reaching the target.
Builds on: Inside a Kubernetes cluster
How a controller replaces a missing Pod
You need three copies of a small web server running. A one-time command could start three processes, but your real requirement lasts all afternoon. If someone deletes a copy at lunch, you still want three. Kubernetes lets you declare that durable target and uses controllers to keep working toward it.
Desired state is what you ask the system to maintain, such as spec.replicas: 3. Observed state is what Kubernetes can see or report at the moment, such as three Pod objects with only two ready. Reconciliation is the controller loop that reads the target and the current state, acts on the difference, and checks again. An event can prompt the next check. The check uses the state the controller can read, which may already be newer than the event.
The example is a Deployment. Its controller manages a ReplicaSet for the Pod template. The ReplicaSet maintains the count of active Pods it manages. When a managed Pod is deleted, the ReplicaSet can create another one. Each time a replacement is created, it still needs scheduling, an image, container startup, and readiness.
The desired count stays on the Deployment
When a ReplicaSet has fewer active Pods than it should, its controller creates a replacement and observes the result.
Target of three
- ReplicaSet controllerReplicaSet desired: 3read target
- ReplicaSet desired: 3Pod Aowns
- ReplicaSet desired: 3Pod Bowns
The ReplicaSet target is three but only two matching active owned Pods exist. Terminal or deleting Pods do not fill the target. The controller observes a count gap.
One Pod is created
- Pod A
- Pod B
- ReplicaSet controllerPod C: newcreate missing object
- Desired: 3Pod C: newowns
The ReplicaSet controller creates one Pod object. It does not create three more because three was the original request.
Check the actual count again
- Pod C ready
- No count repair neededDesired: 3, observed: 3latest observation
Three active managed Pods now exist. A repeated reconciliation observes no count gap and does not duplicate them. Readiness is still a separate observation.
A Deployment has already set its ReplicaSet target to three; all observed Pods are healthy in this branch.
Explore another case
Declare how many Pods you need
Save the Deployment as reconcile-demo.yaml in a disposable lab directory. replicas: 3 describes the quantity. The template describes each Pod. The label in the template gives the selector something to match. Apply the description and watch the resulting Pods to see these different steps happen.
apiVersion: apps/v1
kind: Deployment
metadata:
name: reconcile-demo
spec:
replicas: 3 # Enduring desired Pod count.
selector:
matchLabels:
app: reconcile-demo
template:
metadata:
labels:
app: reconcile-demo # Must match the selector.
spec:
containers:
- name: web
image: nginx:1.27.5kubectl apply -f reconcile-demo.yaml
kubectl get deployment reconcile-demo
kubectl get rs -l app=reconcile-demo
kubectl get pods -l app=reconcile-demo -wThe Deployment appears after the API accepts the write. During the watch, the desired count may already be three while the ready count is zero. Over time, the observed state can move toward the target. That is convergence. It takes work after the write returns, and the work can get stuck. Stop the watch with Ctrl+C when the Pods are ready.
Try deleting and scaling a workload
Now delete one actual Pod in the demo. List the names first and substitute one of yours. Look for a new Pod name and watch it become ready. At the start of the replacement, the total number of objects you see may include a terminating object. Inspect the status as well as the count.
kubectl get pods -l app=reconcile-demo
# Replace the example name with one actual Pod name from that listing.
kubectl delete pod ACTUAL_POD_NAME
kubectl get pods -l app=reconcile-demo -o wideWhat replaces a deleted Pod?
A ReplicaSet creates a Pod when an active member disappears. The replacement has a new identity and must start up.
- Lab operatorDelete one PodAPI serverThe desired replica count remains three.
- ReplicaSet controllerCreate the replacementPod DThe new Pod has its own name and UID.
- Worker kubeletStart its containerReplacement PodThe new member becomes ready after startup.
A ReplicaSet creates a Pod when an active member disappears. The replacement has a new identity and must start up.
One Pod is deleted from a healthy three-replica workload; termination overlap is simplified.
Explore another case
Deleting a Pod tests what the controller does when a member disappears. To ask for two copies permanently, change the Deployment’s desired replica count. The controller now tries to maintain two. The module lab repeats the experiment and checks that a deleted Pod’s UID disappears.
Read replicas and readiness separately
The ReplicaSet counts active managed Pods. A Pod whose image pull is failing can still count toward that total. Creating additional Pods with the same bad image would reproduce the same issue. If a cluster keeps reporting fewer Ready Pods than desired, examine the failed stage by reading Pod conditions or events. Examples include a node that cannot fit the request, an unavailable registry, or a readiness probe that keeps failing.
Check your understanding
A Deployment asks for three replicas. Three Pods exist, and one shows ImagePullBackOff. What would you change?
Use the failing Pod’s events to diagnose the image reference or registry access. The ReplicaSet already has three active Pods, and the kubelet is retrying the pull for the affected one. Correct the image configuration in the Deployment if that is the cause. Then watch availability recover.
Primary documentation
Go to the source
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise