1 of 26

kubelet

K8S Deep Dive

Kick D2

2 of 26

kubelet

  • 클라이언트
    • of kube-apiserver
  • 서버
    • for kube-apiserver
  • 노드 담당자
    • 노드 등록 및 노드 상태보고
  • 파드 컨트롤러
    • 파드 생성 및 라이프사이클 관리

3 of 26

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

4 of 26

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

5 of 26

Control Loops

6 of 26

Container Runtime

OCI

kubelet

containerd

grpc�client

grpc�server

protobuf

RunC

CRI

High level runtime

Low level runtime

7 of 26

컨테이너 실행 과정

image → bundle → run

8 of 26

컨테이너 실행 과정

CRI

image → bundle → run

OCI

9 of 26

CRI (Container Runtime Interface)

OCI

kubelet

containerd

grpc�client

grpc�server

protobuf

RunC

CRI

High level runtime

Low level runtime

컨테이너 라이프사이클 관리

이미지 관리 및 번들링

컨테이너런타임 실행

10 of 26

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

}

11 of 26

OCI (Open Container Initiative)

OCI

kubelet

containerd

grpc�client

grpc�server

protobuf

RunC

CRI

High level runtime

Low level runtime

OCI 구현체

컨테이너런타임 코드

컨테이너 생성과 실행

12 of 26

OCI 스펙

13 of 26

PLEG, Pod Lifecycle Event Generator

파드 라이프사이클 관리

  1. Pod 스펙에 대한 변경 관리
  2. 컨테이너 상태 관리

14 of 26

PLEG, Pod Lifecycle Event Generator

파드 라이프사이클 관리

  • Pod 스펙에 대한 변경 관리 => Watch
  • 컨테이너 상태 관리

manifests

Pod Spec�(configCh)

Sync�Loop

http://

15 of 26

PLEG, Pod Lifecycle Event Generator

파드 라이프사이클 관리

  • Pod 스펙에 대한 변경 관리
  • 컨테이너 상태 관리 => polling 컨테이너런타임

PLEG

Container Runtime Interface

Runtime Status (RPC)

16 of 26

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

17 of 26

Pod Lifecycle Event

18 of 26

Pod Lifecycle Event Type

19 of 26

PLEG 인터페이스

20 of 26

PLEG 구현체

pkg/kubelet/kubelet/pleg/generic.go

21 of 26

Send PLEG Event

PLEG

CRI

relist

22 of 26

Watch PLEG Event

PLEG

pleg.Watch

(plegCh)

Sync�Loop

CRI

relist

23 of 26

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)

24 of 26

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

25 of 26

Event Channels

  • configCh
  • plegCh
  • syncCh
  • livenessManager.Updates()
  • houseKeepingCh

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())

26 of 26

SyncHandler