Pod Management Process in kubelet

457 단어·3 분·원문(.md)

kubelet is the program that actually runs and maintains the Pods that should be running on this node.

It is the only component in all of Kubernetes responsible for the actual lifecycle management of Pods.

  1. Continuously monitors the desired state as told by the API server
  2. Continuously reconciles the current node state to match the desired state
API Server: “This node should have Pod A”
kubelet:    “Check → If not present, create it; if present, keep it alive; if dead, restart it”

The internal operation of kubelet can be understood as a single loop.

Internally, it continuously runs only the following loop.

desiredPods = Get from API Server
runningPods = Check from actual runtime (containerd)

Calculate difference (diff) → Execute creation / restart / termination

Everything else is merely a side function of this loop.

How kubelet Executes Pods #

  1. Scheduler decides the Pod belongs to this node: kubelet starts its work when the PodSpec nodeName is set to this node.
  2. kubelet detects this by watching the API server: A new Pod is assigned to its node. It registers the Pod in its internal management list, the pod manager.
  3. kubelet Sync Loop creates the Pod
    1. Volume preparation: Prepares necessary pvc, secret, and configmap files
    2. Pod sandbox creation (pause container)
      1. Pod's network configuration based on namespaces
    3. initContainer execution (sequentially): If it fails, the main container will never run.
    4. Main container execution (requests creation from containerd, sets cgroup CPU and memory limits)
    5. Probe connection starts: Updates status after checking readiness and liveness.

kubelet performs this process.

How kubelet Keeps Pods Alive #

kubelet acts like a process monitor.

  • If a container process dies, it restarts it according to the restartPolicy.
  • Restarts the container if LivenessProbe fails.
  • Updates the ready state to false if ReadinessProbe fails.
  • Periodically reports its status to the API Server (StatusManager).

In other words, kubelet monitors and takes action to ensure the Pod remains alive.

How kubelet Terminates Pods #

kubelet removes Pods in the following situations:

  1. Pod deletion request (kubectl delete)
    1. graceful termination
    2. pre stop hook
    3. SIGTERM -> wait -> SIGKILL
  2. Node resource pressure (eviction)
    1. MemoryPressure or DiskPressure occurs
    2. Terminates Pods by priority
    3. In order of BestEffort, Burstable, Guaranteed
  3. Container termination + restartPolicy=never
    1. Maintains Pod in terminated state without further restarts

kubelet acts like a node resource guardian.

Clearly Distinguishing What kubelet Does and Doesn't Do #

What kubelet Does

  • Pod creation, execution, restart, termination
  • volume mount
  • probe execution
  • Calling the container runtime (containerd)
  • Reporting node status
  • Resource pressure-based eviction

What it Doesn't Do

  • Scheduling
  • Traffic routing
  • Load balancing
  • YAML interpretation (these are the controller's responsibilities)

kubelet is solely an agent that verifies and adjusts whether the Pods on this node are alive according to the API server's desired state.

SRE/question/q_13.md