Skip to Content
Mengty Learns
Kubernetes

What Happens on kubectl apply

Trace how kubectl apply flows through the Kubernetes API Server, etcd, controllers, kube-scheduler, kubelet, and the container runtime.

explanationintermediateTested with kubectl 1.36 (docs only), kubernetes 1.36 (docs only)Updated Nov 26, 2026

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

TL;DR

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.

Every component watches and updates state through kube-apiserver; only the API Server talks to etcd.

Solution

Kubernetes uses a level-triggered reconciliation loop centered on kube-apiserver:

  1. kubectl → API Server: kubectl apply sends the manifest (or server-side apply patch) over HTTPS. The API Server runs Authentication, Authorization (RBAC), and Admission (mutating then validating).
  2. API Server → etcd: Once valid, the Deployment object is persisted in etcd.
  3. Controllers (kube-controller-manager): Watching Deployments, the Deployment controller creates or updates a ReplicaSet, whose controller creates Pod objects (still unscheduled, nodeName: "").
  4. Scheduler (kube-scheduler): Watches unscheduled Pods, filters out nodes that lack CPU/memory or fail taints/affinities, scores the remaining nodes, and writes spec.nodeName via the API Server.
  5. kubelet → CRI Runtime: Watching Pods bound to its node, kubelet calls the Container Runtime Interface (CRI) (e.g., containerd) to pull the image, start the container, and report Ready status back to the API Server.

Real-world analogy

▶ Flow: watch it work

Control-Plane & Node Loop on kubectl apply

Overview of Control-Plane & Node Loop on kubectl apply. 6 steps.
Overview6 steps in this flow

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 -w

When to use / when to avoid

When to use
  • 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).
When to avoid
  • 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

Pros
  • 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).
Cons
  • 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