What Happens on kubectl apply
Trace how kubectl apply flows through the Kubernetes API Server, etcd, controllers, kube-scheduler, kubelet, and the container runtime.
TL;DR
kubectl apply does not talk to nodes or containers directly. It sends your YAML to kube-apiserver, which authenticates, authorizes, admits, and writes the desired state to etcd; controllers, kube-scheduler, kubelet, and the CRI runtime then asynchronously reconcile reality to match.
Intent
Understand the asynchronous watch-and-reconcile loop behind kubectl apply, so you know where to look when a Deployment is stuck at Pending, ImagePullBackOff, or 0/1 Ready.
Problem
Many engineers assume kubectl apply is an imperative RPC that immediately starts containers and waits. When a Pod stays Pending or fails admission, guessing blindly wastes time because each stage—API validation, controller creation, scheduling, and node execution—is owned by a separate component.
Solution
Kubernetes uses a level-triggered reconciliation loop centered on kube-apiserver:
kubectl→ API Server:kubectl applysends the manifest (or server-side apply patch) over HTTPS. The API Server runs Authentication, Authorization (RBAC), and Admission (mutating then validating).- API Server →
etcd: Once valid, the Deployment object is persisted inetcd. - Controllers (
kube-controller-manager): Watching Deployments, the Deployment controller creates or updates a ReplicaSet, whose controller creates Pod objects (still unscheduled,nodeName: ""). - Scheduler (
kube-scheduler): Watches unscheduled Pods, filters out nodes that lack CPU/memory or fail taints/affinities, scores the remaining nodes, and writesspec.nodeNamevia the API Server. kubelet→ CRI Runtime: Watching Pods bound to its node,kubeletcalls the Container Runtime Interface (CRI) (e.g.,containerd) to pull the image, start the container, and reportReadystatus back to the API Server.
Real-world analogy
▶ Flow: watch it work
Control-Plane & Node Loop on kubectl apply
Press Start or tap any step dot to trace the path.
▸All steps (6)
Code
You can validate a Deployment manifest locally with kubectl apply --dry-run=client before sending it to a cluster:
# Client-side validation without mutating a cluster (not run against a live cluster)
kubectl apply -f deployment.yaml --dry-run=client -o yaml
# Apply and watch the reconciliation stages
kubectl apply -f deployment.yaml
kubectl get deployment,rs,pods -wWhen to use / when to avoid
- You want declarative, idempotent updates where Kubernetes converges cluster state to your YAML.
- You are debugging why a Pod is stuck in Pending (scheduler), ContainerCreating (kubelet/CRI), or rejected at apply time (API Server).
- You need imperative one-off debugging commands (use kubectl exec, logs, or port-forward instead of apply).
- You want Git to be the single source of truth instead of running kubectl apply from laptops (use GitOps).
How to implement
Author declarative manifests
Define Deployment manifests with resource requests/limits and readiness probes.
Validate before applying
Run kubectl apply --dry-run=client or kubeconform in CI to catch schema errors early.
Apply and inspect events
Run kubectl apply -f ... and check kubectl describe pod <name> if scheduling or image pull stalls.
Pros / Cons
- Resilient by design: if a node or controller restarts, watch loops resume reconciling from etcd.
- Single security boundary: RBAC and admission webhooks enforce policy in one place (kube-apiserver).
- kubectl apply returning 0 only means etcd accepted the desired state, not that Pods are Ready.
- Debugging requires checking multiple layers (API events, ReplicaSet conditions, Pod events, kubelet logs).
Relations
Check yourself
Check Yourself
1. A Pod is stuck in Pending with an event saying '0/3 nodes are available: Insufficient memory'. Which component emitted that?
2. When kubectl apply succeeds immediately, what has actually completed?
Sources
Related Notes
Service Routing: Ingress → Service → Pod
How a Kubernetes request travels from a user's browser through Ingress and Service to a healthy Pod and back.
Pods, ReplicaSets, and Deployments
How Kubernetes layers Pods, ReplicaSets, and Deployments to run stateless workloads and perform zero-downtime rollouts and rollbacks.