Kubelet Reconcile Loop

A Pod lands on a Node and its containers start, and if one dies later, it can come back on its own. What keeps comparing the Pod spec with the containers running on that Node, and fixes any difference?

Play the animation 5 steps, animated, plays on a computer or a tablet

Kubelet Reconcile Loop diagram: Kubelet sync loop

Kubelet Reconcile Loop, step by step

  1. The API streams an ADDED event for Pod my-app-7d4-x2k9p bound to Node-1. The Kubelet merges its spec sources into one update channel, and the sync loop records the Pod in podManager as desired state.

    Play from step 1
  2. PLEG (Pod Lifecycle Event Generator) wakes on its 1s timer, calls ListPodSandbox and ListContainers, and finds no sandbox or container for the new Pod. PLEG records the empty observed state for SyncPod. With EventedPLEG on (alpha feature gate, off by default), the runtime pushes lifecycle events over CRI, so Kubelet relists far less often.

    Play from step 2
  3. The sync loop queued the Pod for its Pod worker goroutine, which now calls SyncPod. SyncPod compares desired state (1 container in spec) against observed state (no sandbox, 0 containers). The diff is two actions: create the Pod sandbox, then create and start the missing container.

    Play from step 3
  4. Kubelet issues CRI gRPC calls in sequence. RunPodSandbox creates the pause container with shared namespaces, then PullImage fetches the image, a call imagePullPolicy can skip when the image is already on the Node. CreateContainer and StartContainer then launch each container in the spec. The Pod Sandbox via CRI card details the sandbox setup.

    Play from step 4
  5. Right after that sync the Kubelet asks PLEG to relist the Pod (beta PLEGOnDemandRelist gate, on by default), so it sees the running container without waiting for the 1s timer. Observed state catches up to desired state. SyncPod finds nothing left to create or start, and Kubelet PATCHes Pod status again, this time with the running container in containerStatuses.

    Play from step 5

Sources