Skip to content

Commit 7edffe7

Browse files
lauralorenzlmktfy
andauthored
Update pod lifecycle docs (#54177)
* Add kubelet details to pod lifecycle docs Signed-off-by: lauralorenz <lauralorenz@google.com> * Add section for kubelet implementation details Signed-off-by: lauralorenz <lauralorenz@google.com> * Add more detail including a deep link Signed-off-by: lauralorenz <lauralorenz@google.com> * Match style guide Signed-off-by: lauralorenz <lauralorenz@google.com> * Rewrap Signed-off-by: lauralorenz <lauralorenz@google.com> * Another rewrap Signed-off-by: lauralorenz <lauralorenz@google.com> * Better tooltip location suggestion Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com> * Move medium-level information to node reference page Signed-off-by: lauralorenz <lauralorenz@google.com> * Break up complex sentence Signed-off-by: Laura Lorenz <lauralorenz@google.com> * Simplify link name Signed-off-by: Laura Lorenz <lauralorenz@google.com> * Remove deep link and fix formatting Signed-off-by: Laura Lorenz <lauralorenz@google.com> * Kick netlify Signed-off-by: Laura Lorenz <lauralorenz@google.com> --------- Signed-off-by: lauralorenz <lauralorenz@google.com> Signed-off-by: Laura Lorenz <lauralorenz@google.com> Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com>
1 parent 385b513 commit 7edffe7

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

content/en/docs/concepts/workloads/pods/pod-lifecycle.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ in the `Pending` [phase](#pod-phase), moving through `Running` if at least one
1212
of its primary containers starts OK, and then through either the `Succeeded` or
1313
`Failed` phases depending on whether any container in the Pod terminated in failure.
1414

15+
While a Pod runs, the kubelet manages containers and translates the Pod's spec
16+
for the container runtime. The kubelet also manages executing
17+
[probes](#container-probes) that track the health of your application.
18+
1519
Like individual application containers, Pods are considered to be relatively
1620
ephemeral (rather than durable) entities. Pods are created, assigned a unique
1721
ID ([UID](/docs/concepts/overview/working-with-objects/names/#uids)), and scheduled
@@ -25,10 +29,14 @@ plane marks the Pods for removal after a timeout period.
2529

2630
## Pod lifetime
2731

28-
Whilst a Pod is running, the kubelet is able to restart containers to handle some
29-
kind of faults. Within a Pod, Kubernetes tracks different container
32+
Whilst a Pod is running, the kubelet is able to restart containers to handle
33+
some kind of faults. Within a Pod, Kubernetes tracks different container
3034
[states](#container-states) and determines what action to take to make the Pod
31-
healthy again.
35+
healthy again. This is done in a [polling
36+
loop](/docs/reference/node/kubelet-sync-loop/) that periodically reconciles the
37+
desired state (a Pod spec) with the actual state of the running containers.
38+
Because of this polling mechanism, the status seen in the API (like `kubectl get
39+
pod`) might have a slight delay compared to the instant reality on the node.
3240

3341
In the Kubernetes API, Pods have both a specification and an actual status. The
3442
status for a Pod object consists of a set of [Pod conditions](#pod-conditions).
@@ -129,11 +137,16 @@ A Pod is granted a term to terminate gracefully, which defaults to 30 seconds.
129137
You can use the flag `--force` to [terminate a Pod by force](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-forced).
130138
{{< /note >}}
131139

132-
Since Kubernetes 1.27, the kubelet transitions deleted Pods, except for
133-
[static Pods](/docs/tasks/configure-pod-container/static-pod/) and
134-
[force-deleted Pods](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-forced)
135-
without a finalizer, to a terminal phase (`Failed` or `Succeeded` depending on
136-
the exit statuses of the pod containers) before their deletion from the API server.
140+
Since Kubernetes 1.27, the kubelet transitions deleted Pods to a terminal phase
141+
(`Failed` or `Succeeded` depending on the exit statuses of the pod containers)
142+
before their deletion from the API server, with two exceptions:
143+
144+
* [static Pods](/docs/tasks/configure-pod-container/static-pod/) (which are
145+
managed directly by the kubelet and represented by {{< glossary_tooltip
146+
text="mirror Pods" term_id="mirror-pod" >}})
147+
* [force-deleted
148+
Pods](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-forced)
149+
without a finalizer
137150

138151
If a node dies or is disconnected from the rest of the cluster, Kubernetes
139152
applies a policy for setting the `phase` of all Pods on the lost node to Failed.

content/en/docs/reference/node/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ no_list: true
66

77
This section contains the following reference topics about nodes:
88

9+
* the kubelet's [sync loop](/docs/reference/node/kubelet-sync-loop/)
10+
911
* the kubelet's [checkpoint API](/docs/reference/node/kubelet-checkpoint-api/)
12+
1013
* a list of [Articles on dockershim Removal and on Using CRI-compatible Runtimes](/docs/reference/node/topics-on-dockershim-and-cri-compatible-runtimes/)
1114

1215
* [Kubelet Device Manager API Versions](/docs/reference/node/device-plugin-api-versions)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
content_type: "reference"
3+
title: Kubelet Sync Loop
4+
weight: 42
5+
---
6+
7+
The [kubelet](/docs/reference/command-line-tools-reference/kubelet/) is the
8+
primary "node agent" that creates and watches Pods on each node. The `kubelet`
9+
runs a sync loop that periodically reconciles the desired state (a Pod spec)
10+
with the actual state of the running containers.
11+
12+
1. **Sync Loop**: The Sync Loop queues work (aggregated from many sources) for
13+
the Pods assigned to its node (where `nodeName` matches the node). Over the
14+
course of each loop, subprocesses called pod workers will attempt to
15+
reconcile the desired state of these Pods against the current state of the
16+
running containers.
17+
2. **Sync Pod**: The majority of the `kubelet` logic is stored in a suite of
18+
functions within the `podSyncer` interface, including the `SyncPod` function
19+
and its variants (like `SyncTerminatingPod` and `SyncTerminatedPod`). During
20+
each Sync Loop, a relevant `podSyncer` function will be executed for each Pod
21+
in an attempt to drive its state on the node toward the desired state.
22+
3. **{{< glossary_tooltip term_id="cri" text="Container Runtime Interface" >}}
23+
(CRI)**: To actually run the containers, the `kubelet` uses the CRI to talk
24+
to a container runtime (like containerd or CRI-O). The `kubelet` acts as the
25+
client, instructing the runtime to create a "pod sandbox" and then
26+
create/start the individual containers defined in the Pod spec.
27+
4. **PLEG (Pod Lifecycle Event Generator)**: The `kubelet` needs to know when
28+
containers start, stop, or fail. It relies on a component called PLEG to
29+
periodically poll the runtime for the standard state of all containers. PLEG
30+
generates events that wake up the Sync Loop to update the Pod status.
31+
32+
Because of this polling mechanism, the status seen in the API (like `kubectl get
33+
pod`) might have a slight delay compared to the instant reality on the node.

0 commit comments

Comments
 (0)