说明:此文章为腾讯云机器自动从本人csdn博客搬迁过来。是本人授权操作。
申明:无本人授权,不可转载本文。如有转载,本人保留追究其法律责任的权利。
龚浩华,QQ 29185807,月牙寂 道长
第一时间获取文章,可以关注本人公众号 月牙寂道长 yueyajidaozhang
代码在k8s.io\kubernetes\pkg\kubelet\kubelet.go中
func NewMainKubelet(
很简单,参数就是kubeclient,与apiserver连接的接口,就不再详细分析了。
我们再看下启动
// Run starts the kubelet reacting to config updates
func (kl *Kubelet) Run(updates <-chan PodUpdate) {
在Run中启动的
代码在k8s.io\kubernetes\pkg\kubelet\status下
先NewManager
我们看看结构体
podStatuses:用于保存podstatus
podStatusChannel:用于模块间通信用
再看看对外暴露的接口
下面我们一个一个来进行解析
// Start the API server status sync loop.
开启与api server的同步任务
开启了一个定时任务syncBatch
继续跟踪
从podStatusChannel中获取到请求请求任务
然后通过kubeclient获取最新的状态
获取到最新状态之后,进行更新,并判断是否terminated,再判断是否正在运行,没有这删除
最后,如果操作失败,则删除,等待下次操作。
// GetPodStatus returns the cached status for the provided pod UID,
//as well as whether it was a cache hit.
这个很简单,直接从map中查找,返回结果
// SetPodStatus caches updates the cached status for the given pod,
//and triggers a status update.
更新caches,并触发状态更新
从caches(map)中查找,查找不到,则赋值启动时间
然后放入到caches(map)中,并通过podStatusChannel发布一个任务请求。这个将在start启动的同步任中获取到
// TerminatePods resets the container status for the provided pods
//to terminated and triggers
// a status update. This function may not enqueue all the provided pods,
//in which case it will
// return false
终止一个pod,并触发一个终止任务
设置pod的Terminated状态。然后通过podStatusChannel触发任务。如果发送失败则返回false,可以通过下次再一次尝试
// DeletePodStatus simply removes the given pod from the status cache.
删除一个podstatus,主要是从caches(map)中删除
// RemoveOrphanedStatuses scans the status cache and removes any entries
//for pods not included in
// the provided podUIDs.
也是一个删除操作,从caches(map)中删除
statusManager功能单一,逻辑清晰,通过暴露接口向外提供操作。是典型的golang设计模式。