Kubelet 的创建
在CreateAndInitKubelet方法中
1. 调用 kubelet.NewMainKubelet(pkg/kubelet/kubelet.go)方法,创建kubelet对象;
2. 调用 BirthCry,发送一个事件,宣告 kubelet 已经成功启动;
3. 调用 StartGarbageCollection,启动 kubelet GC 流程
4. 返回创建好的kubelet对象
kubelet 的创建
NewMainKubelet 主要的工作就是创建 Kubelet 这个对象,它包含了 kubelet 运行需要的所有对象,现在有600行左右的代码,下面列举一些比较重要的对象。
• 创建 config.PodConfig (通过 makePodSourceConfig)

PodConfig 非常重要,它是 pod 信息的来源,kubelet 支持文件、URL 和 apiserver 三种渠道,PodConfig 将它们汇聚到一起,通过管道来传递。
PodConfig 实现了Mux接口,Mux框架用来合并多个数据源,当任何一个数据源有更新时,都会促发Mux的Merge函数用来合并更新的信息,这里podCfg的数据源,即kubetypes.FileSource、kubetypes.HTTPSource和kubetypes.ApiserverSource;Merge函数会把合并后的Pod信息输入到s.updates这个channel中;
PodConfig 的 pods 是 podStorage 类型,它应该有一份所有pods的缓存。
• ServiceLister:能够读取 kubernetes 中服务信息
• nodeLister:能够读取 apiserver 中节点的信息

• secretManager:secret 资源的管理
• configMapManager:configMap 资源的管理
• InitNetworkPlugin:网络插件的初始化

• podManager:缓存了 pod 的信息,是所有需要该信息都会去访问的地方

• probeManager:如果 pod 配置了状态监测,那么 probeManager会定时检查 pod 是否正常工作,并通过 statusManager 向 apiserver 更新 pod 的状态

• volumeManager:负责容器需要的 volume 管理。检测某个 volume 是否已经 mount、获取 pod 使用的 volume 等

• containerRuntime:容器运行时,对容器引擎(docker 或者 rkt)的一层封装,负责调用容器引擎接口管理容器的状态,比如启动、暂停、杀死容器等
• containerGC:进行周期性的容器清理工作
• imageManager:管理镜像
• statusManager:向 apiserver 更新 pod 的状态

• podWorkers:具体的执行者,每次有 pod 需要更新的时候都会发送给它
• setNodeStatusFuncs:用于汇报节点的情况
• evictionManager:负责容器的驱逐

BirthCry
暂略
StartGarbageCollection
暂略
返回创建好的kubelet对象
实现了Kubelet.Bootstrap接口
