kubelet
K8S Deep Dive
Kick D2
kubelet
kubelet architecture
Kubelet API
:10250
:10255
:10248
secure
read-only
healthz
PLEG
PodManager
cAdvisor
OOMWatcher
ProbeManager
EvictionManager
StatusManager
VolumeManager
Image GC
ImageManager
Container GC
CertificateManager
CRI
OCI
CNI
CSI
Sync�Loop
PodWorker Pool
Prober
NodeManager
PluginManager
kubelet API
/metrics
/metrics/cadvisor
/metrics/resource/v1alpha1
/metrics/probes
/spec/
/stats/
/logs/ (secure-port only)
/pods
/configz (kubelet’s configuration endpoint)
/run/*
/exec/*
/attach/*
/portForward/*
/containerLogs/*
/runningpods/
/cri/
:10250
:10255
:10248
secure
read-only
healthz
Control Loops
Container Runtime
OCI
kubelet
containerd
grpc�client
grpc�server
protobuf
RunC
CRI
High level runtime
Low level runtime
컨테이너 실행 과정
image → bundle → run
컨테이너 실행 과정
CRI
image → bundle → run
�
OCI
CRI (Container Runtime Interface)
OCI
kubelet
containerd
grpc�client
grpc�server
protobuf
RunC
CRI
High level runtime
Low level runtime
컨테이너 라이프사이클 관리
이미지 관리 및 번들링
컨테이너런타임 실행
CRI 인터페이스
service ImageService {
rpc ListImages
rpc ImageStatus
rpc PullImage
rpc RemoveImage
rpc ImageInfo
}
service RuntimeService {
rpc Version
rpc RunPodSandbox
rpc StopPodSandbox
rpc RemovePodSandbox
rpc PodSandboxStatus
rpc ListPodSandbox
rpc CreateContainer
rpc StartContainer
rpc StopContainer
rpc RemoveContainer
rpc ListContainers
rpc ContainerStatus
rpc ContainerResources
rpc ExecSync
rpc Exec
rpc Attach
rpc PortForward
rpc ContainerStats
rpc ListContainerStats
rpc UpdateRuntimeConfig
rpc Status
}
OCI (Open Container Initiative)
OCI
kubelet
containerd
grpc�client
grpc�server
protobuf
RunC
CRI
High level runtime
Low level runtime
OCI 구현체
컨테이너런타임 코드
컨테이너 생성과 실행
OCI 스펙
PLEG, Pod Lifecycle Event Generator
파드 라이프사이클 관리
PLEG, Pod Lifecycle Event Generator
파드 라이프사이클 관리
manifests
Pod Spec�(configCh)
Sync�Loop
http://
PLEG, Pod Lifecycle Event Generator
파드 라이프사이클 관리
PLEG
Container Runtime Interface
Runtime Status (RPC)
PLEG, Pod Lifecycle Event Generator
PLEG
manifests
Pod Spec�(configCh)
Pod event
(plegCh)
Container Runtime Interface
create / kill
examine containers
http://
Sync�Loop
PodWorker Pool
(periodic re-list)
Pod ID�(UpdateOptions)
event stream
docker api
cAdvisor
Pod Lifecycle Event
Pod Lifecycle Event Type
PLEG 인터페이스
PLEG 구현체
pkg/kubelet/kubelet/pleg/generic.go
Send PLEG Event
PLEG
CRI
relist
Watch PLEG Event
PLEG
pleg.Watch
(plegCh)
Sync�Loop
CRI
relist
kubelet architecture
PLEG
(housekeepingCh)
manifests
(syncCh)
Pod Spec�(configCh)
Pod event
(plegCh)
PodWorker Pool
Pod Cache
Container Runtime Interface
Prober
Runtime Operation (RPC)
(periodic) relist�pods / containers (compare)
Pod�Re-sync
house�keeping
http://
Sync�Loop
event stream
docker api
cAdvisor
주기적으로 spec과 status를 비교하여 SyncLoop의 이벤트 트리거 보완
relist 보완. pods/containers 관련 정보를 이벤트 기반으로 빠르게 캐치할 목적
Unwanted, Terminating Pods 등 Cleanup
container (app) liveness, readiness check (http, tcp, exec)
SyncLoop
Arguments:
// 1. configCh: a channel to read config events from
// 2. handler: the SyncHandler to dispatch pods to
// 3. syncCh: a channel to read periodic sync events from
// 4. housekeepingCh: a channel to read housekeeping events from
// 5. plegCh: a channel to read PLEG updates from
Sync�Loop
Event Channels
handler.HandlePodSyncs([]*v1.Pod{pod})
handler.HandlePodAdditions(u.Pods)
handler.HandlePodUpdates(u.Pods)
handler.HandlePodRemoves(u.Pods)
handler.HandlePodReconcile(u.Pods)
handler.HandlePodUpdates(u.Pods)
cleanUpContainersInPod(e.ID, container.ID)
lastContainerStartedTime.Add(e.ID, time.Now())
SyncHandler