kubelet VolumeManager 流程

云计算 waitig 546℃ 百度已收录 0评论

1.govm.desiredStateOfWorldPopulator.Run(sourcesReady,stopCh)podmangerpod挂载的volume信息同步到desiredStateOfWorld

2.govm.reconciler.Run(stopCh)执行volumedetach/attach/mount/unmount操作,同步已经挂载好的volume信息到desiredStateOfWorldactualStateOfWorld

type desiredStateOfWorld struct {
   volumekeyvaluevolume对应的pod信息和node信息
   volumesToMount map[v1.UniqueVolumeName]volumeToMount
   volume对应的plugin
   volumePluginMgr *volume.VolumePluginMgr
   sync.RWMutex
}
type volumeToMount struct {
   volumeName v1.UniqueVolumeName
   podkeyvaluepod及其需要挂载的volume信息
   podsToMount map[types.UniquePodName]podToMount
   volume plugin是否支持attach
   pluginIsAttachable bool
   // volumeGidValue contains the value of the GID annotation, if present.
   volumeGidValue string
   // reportedInUse indicates that the volume was successfully added to the
   // VolumesInUse field in the node's status.
   reportedInUse bool
}
type podToMount struct {
   // podName contains the name of this pod.
   podName types.UniquePodName
   pod详情
   pod *v1.Pod
   volume详情
   spec *volume.Spec
   outerVolumeSpecName string
}

.govm.desiredStateOfWorldPopulator.Run(sourcesReady,stopCh)

1.调用populatorLoopFuncpodvolume的信息同步到desiredStateOfWorld中。

1.1调用findAndAddNewPods遍历pod并将podpod上的volume信息node信息加入到desiredStateOfWorld结构体中。

1.1.1调用desiredStateOfWorld.AddPodToVolumepod加入desiredStateOfWorld

1.2调用findAndRemoveDeletedPods将不再存在的poddesiredStateOfWorld删除

1.2.1遍历desiredStateOfWorld中期望被挂载的volume

1.2.2假如pod不存在了,并且pod对应的container也不再running,调用desiredStateOfWorld.DeletePodFromVolumepoddesiredStateOfWorld删除,还调用deleteProcessedPodpoddeleteProcessedPod中删除,deleteProcessedPod是存放已经处理过的pods

.govm.reconciler.Run(stopCh)

调用reconciliationLoopFunc进行mountunmount操作

1调用reconcile()确保需要mountvolumemount,需要unmountvolumeunmount

1.1调用actualStateOfWorld.GetMountedVolumes()获取已经挂载的volume,如果该volume不在desiredStateOfWorld,即不期望被挂载,则把该volumeumount

1.1.1调用volumeUnmounter.TearDown()volumefsgroup挂载点上umount

1.1.2调用MarkVolumeAsUnmountedvolume标记为已经从fsgroup挂载点上umount

1.2调用desiredStateOfWorld.GetVolumesToMount()获取所有期望被挂载的volume

1.2.1假如volume没有被attach,并且controllerAttachDetachEnabled开关被打开了,即不允许kubelet去挂载volume,得等待controllermanager去挂载。还调用VerifyControllerAttachedVolume去判断node的挂载情况(获取node的挂载信息,假如node的挂载信息中存在某个期望被挂载的volume,则将该volume标记为已经挂载了,即将volume加入actualStateOfWorld

1.2.2假如该volume需要被挂载,并且volume对应的plugin支持attach操作,并且kubelet能够执行attach操作,则调用operationexecutor.AttachVolumevolume挂载相应的node上,即调用volumeAttacher.Attach执行pluginattach操作,并将该volume标记为已经挂载了,即将volume加入actualStateOfWorld

1.2.3假如该volumeattach了,但是没有被mount。则调用operationExecutor.MountVolume执行mount操作。

1.2.3.1调用volumeAttacher.WaitForAttach等待volume挂载成功,并获取在node上的挂载点

1.2.3.2调用volumeAttacher.GetDeviceMountPath获取mount点(globalmount
path

1.2.3.3调用volumeAttacher.MountDevicemountvolume

1.2.3.4调用actualStateOfWorld.MarkDeviceAsMounted将该volume标记为已经mountglobalmount
path
了,即设置actualStateOfWorldvolume对应的globallyMountedtrue

1.2.3.5调用volumeMounter.SetUp(fsGroup)执行mount操作,即将该volumemountfsgroup里的目录,能够让pod中的容器访问

1.2.3.5.1调用makeGlobalPDName获取mount点(globalmount
path
)即1.2.3.2mount

1.2.3.5.2调用GetPath()获取在fsgroup中该volume需要被挂载的点,

1.2.3.5.3调用Mountglobalmount
path
点挂载到fsgroup中的挂载点

1.2.3.6调用MarkVolumeAsMountedvolume标记为mounted,即设置actualStateOfWorldvolume对应的mountedPods,将mount的挂载信息包含挂载点更新到actualStateOfWorld

1.2.4调用actualStateOfWorld.GetUnmountedVolumes()获取所有需要被mount的但又没有被mountvolume(已经attached了),并且该volume不在desiredStateOfWorld中,即

1.2.4.1假如该volume挂载globalmount
path
了,则调用operationExecutor.UnmountDevicevolumeglobalmountpath卸载,并调用actualStateOfWorld.MarkDeviceAsUnmounted将该volume标记为没有挂载到globalmount
path

1.2.4.2假如kubelet不允许detachvolume则调用actualStateOfWorld.MarkVolumeAsDetached将该volume标记为detach的,即从actualStateOfWorld删除

1.2.4.3假如kubelet允许detachvolume则调用operationExecutor.DetachVolumevolumedetach掉,并调用MarkVolumeAsDetached将该volume标记为detach的,即从actualStateOfWorld删除

volume —> instance path —> global path —>
fsgrouppath

卸载

1.operationExecutor.UnmountVolume端开globalpath
—> fsgroup path

actualStateOfWorld.MarkVolumeAsUnmounted标记

2.operationExecutor.UnmountDevice断开instancepath
—> global path

actualStateOfWorld.MarkDeviceAsUnmounted标记

3.operationExecutor.DetachVolume断开volume
—> instance path

actualStateOfWorld.MarkVolumeAsDetached标记

挂载

1.operationExecutor.AttachVolume连接volume
—> instance path

actualStateOfWorld.MarkVolumeAsAttached标记
2.operationExecutor.MountVolume连接instance path   --->    global path    ---> fsgroup path
volumeAttacher.MountDevice连接instance path   --->    global path
actualStateOfWorld.MarkDeviceAsMounted标记
volumeMounter.SetUp(fsGroup)连接 global path    ---> fsgroup path
 actualStateOfWorld.MarkVolumeAsMounted标记

调用syncStates(podsDir)同步pod的信息和volume信息到actualStateOfWorldvolume中,包含挂载点等信息
1.调用getVolumesFromPodDirkubeletpod目录获取podpod对应的volume信息,including pod's uid, volume's plugin name, mount path, and volume spec name.
2. 调用reconstructVolume获取volume的详情,构建一个volume的结构体
3.将存在于actualStateOfWorldvolume加入volumesNeedUpdate,调用updateStates更新volumesNeedUpdatevolume的信息

4.获取node详情的node.Status.VolumesAttached,更新volumesNeedUpdatevolumeDevicePath信息

5.调用desiredStateOfWorld.GetVolumesToMount()获取期望的volume信息,更新volumesNeedUpdatevolumeOuterVolumeSpecName信息

6.依次调用actualStateOfWorld.MarkVolumeAsAttachedvolume标记为attached

7.依次将pod的信息加入的actualStateOfWorld中对应的volume

8.调用actualStateOfWorld.MarkDeviceAsMountedvolume标记为已挂载到节点上了

9.调用desiredStateOfWorld.AddPodToVolumevolume的信息加入desiredStateOfWorld


本文由【waitig】发表在等英博客
本文固定链接:kubelet VolumeManager 流程
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)