真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

如何實(shí)現(xiàn)Pod的創(chuàng)建和管理

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)如何實(shí)現(xiàn)Pod的創(chuàng)建和管理,文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

創(chuàng)新互聯(lián)建站是一家專(zhuān)注于成都做網(wǎng)站、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),貢井網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:貢井等地區(qū)。貢井做網(wǎng)站價(jià)格咨詢(xún):18980820575

Pod同步流程是kubelet進(jìn)程的核心主流程,下面將分析該主流程中最關(guān)鍵的部分--Pod的創(chuàng)建和管理。這部分邏輯封裝在kubeGenericRuntimeManager.SyncPod(kuberuntime_manager.go)方法中,主要執(zhí)行以下步驟:

  1. 根據(jù)從API Server獲得的Pod Spec以及當(dāng)前Pod的Status計(jì)算所需要執(zhí)行的Actions

  2. 在需要情況下Kill掉當(dāng)前Pod

  3. 根據(jù)需要(如重啟)kill掉pod內(nèi)的containers

  4. 根據(jù)需要?jiǎng)?chuàng)建Pod的sandbox container

  5. 啟動(dòng)下一個(gè)init container

  6. 啟動(dòng)Pod內(nèi)的containers

其中比較復(fù)雜的步驟解釋如下:

1.computePodActions

對(duì)比spec和status,計(jì)算出要達(dá)到預(yù)期狀態(tài)所需的actions:

// computePodActions checks whether the pod spec has changed and returns the changes if true.

func (m *kubeGenericRuntimeManager) computePodActions(pod *v1.Pod, podStatus *kubecontainer.PodStatus) podActions {

   // 1. 對(duì)比sandbox狀態(tài),計(jì)算是否需要?jiǎng)?chuàng)建sandbox,以及當(dāng)前sandbox id

   createPodSandbox, attempt, sandboxID := m.podSandboxChanged(pod, podStatus)

   changes := podActions{

      KillPod:           createPodSandbox,

      CreateSandbox:     createPodSandbox,

      SandboxID:         sandboxID,

      Attempt:           attempt,

      ContainersToStart: []int{},

      ContainersToKill:  make(map[kubecontainer.ContainerID]containerToKillInfo),

   }

 

   // 2. 需要新建sandbox,一旦進(jìn)入該分支就必定return,之后代碼不再執(zhí)行

   if createPodSandbox {

      ....

      // 在新建sandbox分支中,若存在init容器,則取第一個(gè),返回

     if len(pod.Spec.InitContainers) != 0 {

         // Pod has init containers, return the first one.

         changes.NextInitContainerToStart = &pod.Spec.InitContainers[0]

         return changes

      }

       

      // 不存在init容器,直接跑工作containers

      for idx, c := range pod.Spec.Containers {

         if containerSucceeded(&c, podStatus) && pod.Spec.RestartPolicy == v1.RestartPolicyOnFailure {

            continue

         }

         changes.ContainersToStart = append(changes.ContainersToStart, idx)

      }

      return changes

   }

 

   // 3. sandbox已運(yùn)行,啟動(dòng)init容器。尋找下一個(gè)需要執(zhí)行的init容器

   initLastStatus, next, done := findNextInitContainerToRun(pod, podStatus)

   if !done {

      if next != nil {

         initFailed := initLastStatus != nil && isContainerFailed(initLastStatus)

         if initFailed && !shouldRestartOnFailure(pod) {

            changes.KillPod = true

         else {

            changes.NextInitContainerToStart = next

         }

      }

      // 若init未完成,直接返回

      return changes

   }

 

   // 4. init已完成,計(jì)算需要kill&start的工作container

   keepCount := 0

   for idx, container := range pod.Spec.Containers {

   .....

   }

 

   // 5. 是否需要kill pod

   if keepCount == 0 && len(changes.ContainersToStart) == 0 {

      changes.KillPod = true

   }

 

   return changes

}

2. SyncPod

該方法是pod管理的關(guān)鍵,實(shí)現(xiàn)了本文開(kāi)頭講的六個(gè)步驟:

func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) (result kubecontainer.PodSyncResult) {

   // 1. 計(jì)算pod actions,見(jiàn)上文

   podContainerChanges := m.computePodActions(pod, podStatus)

   .....

 

   // 2. 需要情況下執(zhí)行kill pod

   if podContainerChanges.KillPod {

      ....

      killResult := m.killPodWithSyncResult(pod, kubecontainer.ConvertPodStatusToRunningPod(m.runtimeName, podStatus), nil)

      ....

   else {

      // 3. 不需要kill pod,但需要kill工作container

      for containerID, containerInfo := range podContainerChanges.ContainersToKill {

         ....

         if err := m.killContainer(pod, containerID, containerInfo.name, containerInfo.message, nil); err != nil {

            ...

            return

         }

      }

   }

 

   .....

 

   // 4. 按需創(chuàng)建sandbox

   podSandboxID := podContainerChanges.SandboxID

   if podContainerChanges.CreateSandbox {

      .....

      podSandboxID, msg, err = m.createPodSandbox(pod, podContainerChanges.Attempt)

      ....

   }

 

   ....

 

   // 5. 運(yùn)行next init container

   if container := podContainerChanges.NextInitContainerToStart; container != nil {

      ....

      if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {

         startContainerResult.Fail(err, msg)

         utilruntime.HandleError(fmt.Errorf("init container start failed: %v: %s", err, msg))

         return

      }

      ....

   }

 

   // 6. 運(yùn)行工作containers。注意,根據(jù)computePodActions,若NextInitContainerToStart不為空,則不存在ContainersToStart ,即這個(gè)循環(huán)在當(dāng)前這個(gè)SyncPod中不會(huì)被執(zhí)行

   for _, idx := range podContainerChanges.ContainersToStart {

      ....

      if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {

         startContainerResult.Fail(err, msg)

         // known errors that are logged in other places are logged at higher levels here to avoid

         // repetitive log spam

         switch {

         case err == images.ErrImagePullBackOff:

            glog.V(3).Infof("container start failed: %v: %s", err, msg)

         default:

            utilruntime.HandleError(fmt.Errorf("container start failed: %v: %s", err, msg))

         }

         continue

      }

   }

 

   return

}

SyncPod中需要特別注意的是:在init containers啟動(dòng)過(guò)程中,SyncPod每次只會(huì)運(yùn)行一個(gè)init container(next),之后就返回了。

上述就是小編為大家分享的如何實(shí)現(xiàn)Pod的創(chuàng)建和管理了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


分享題目:如何實(shí)現(xiàn)Pod的創(chuàng)建和管理
轉(zhuǎn)載來(lái)于:http://weahome.cn/article/podsih.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部