Kubernetes coreLesson 2 of 13
Desired State and the Control Loop
You do not tell Kubernetes "do this". You write down "it should look like this", and controllers keep comparing that with how things are now and fix the difference. Follow this comparison loop, and how resources find each other with labels and selectors. How a Pod starts, part by part, is covered in How a Pod Starts.
Desired (spec)3
Current (status)0
Controller decision—
Service targets—
RequestResponse / reportWatchAppears in a later step
What you will learn
- Imperative vs declarative
- Why you read spec and status side by side
- A control loop repeats "compare → act"
- An unreachable goal means waiting, not an error
- Resources connect by labels, not names
Myths and facts
| Common myth | In reality |
|---|---|
| If apply succeeds, all Pods are up | Only the desired state is recorded. The actual state takes time to catch up |
| Lack of resources causes an error | No error. Pods wait as Pending and keep retrying until room opens up |
| Users edit status too | Kubernetes fills status. Users write only spec |
| A Service finds targets by Pod name | It uses a label selector. New Pods with matching labels join automatically |
| A wrong selector is rejected on save | It saves fine, with 0 targets |
The control loop actually bringing a Pod back continues in When a Pod Dies (Self-Healing).
Try it yourself
kubectl create deployment demo-web --image=nginx --replicas=3 # Submit the desired state (throwaway)
kubectl get deploy demo-web # READY: current/desired
kubectl get deploy demo-web -o jsonpath='{.spec.replicas} {.status.readyReplicas}{"\n"}' # spec vs status
kubectl get svc <service> -o jsonpath='{.spec.selector}' # Which labels the Service selects
kubectl get endpointslices -l kubernetes.io/service-name=<service> # 0 endpoints? Suspect the selector
kubectl delete deployment demo-web # Cleanup
Check yourself
Further reading: Controllers (Kubernetes docs) · Labels and Selectors · How a Pod Starts · When a Pod Dies (Self-Healing)