首页 > 其他分享 >测试

测试

时间:2022-11-22 10:46:11浏览次数:44  
标签:Terminated 容器 状态 Running 测试 Pod 节点

<h1>六、pod的生命周期</h1>
<div class="lake-content" typography="classic">
  <p id="u09d728bc" class="ne-p"><img src="https://cdn.nlark.com/yuque/0/2022/png/29649025/1666799737558-78e4de33-deb3-4f07-8eb4-885d45ed8cca.png" width="1263.2" id="ufa8b61b9" class="ne-image"></p>
  <p id="u1d159fd3" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">和一个个独立的应用容器一样,Pod 也被认为是相对临时性(而不是长期存在)的实体。 Pod 会被创建、赋予一个唯一的 ID(</span><a href="https://kubernetes.io/zh-cn/docs/concepts/overview/working-with-objects/names/#uids" data-href="https://kubernetes.io/zh-cn/docs/concepts/overview/working-with-objects/names/#uids" target="_blank" class="ne-link"><span class="ne-text">UID</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">), 并被调度到节点,并在终止(根据重启策略)或删除之前一直运行在该节点。</span></p>
  <p id="u13d0d4e4" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">如果一个</span><a href="https://kubernetes.io/zh-cn/docs/concepts/architecture/nodes/" data-href="https://kubernetes.io/zh-cn/docs/concepts/architecture/nodes/" target="_blank" class="ne-link"><span class="ne-text">节点</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">死掉了,调度到该节点的 Pod 也被计划在给定超时期限结束后</span><a href="https://kubernetes.io/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-garbage-collection" data-href="https://kubernetes.io/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-garbage-collection" target="_blank" class="ne-link"><span class="ne-text">删除</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">。</span></p>
  <p id="u6c96d809" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">Pod 自身不具有自愈能力。如果 Pod 被调度到某</span><a href="https://kubernetes.io/zh-cn/docs/concepts/architecture/nodes/" data-href="https://kubernetes.io/zh-cn/docs/concepts/architecture/nodes/" target="_blank" class="ne-link"><span class="ne-text">节点</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">而该节点之后失效, Pod 会被删除;类似地,Pod 无法在因节点资源耗尽或者节点维护而被驱逐期间继续存活。 Kubernetes 使用一种高级抽象来管理这些相对而言可随时丢弃的 Pod 实例, 称作</span><a href="https://kubernetes.io/zh-cn/docs/concepts/architecture/controller/" data-href="https://kubernetes.io/zh-cn/docs/concepts/architecture/controller/" target="_blank" class="ne-link"><span class="ne-text">控制器</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">。</span></p>
  <p id="ucc2e9e0f" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">任何给定的 Pod (由 UID 定义)从不会被“重新调度(rescheduled)”到不同的节点; 相反,这一 Pod 可以被一个新的、几乎完全相同的 Pod 替换掉。 如果需要,新 Pod 的名字可以不变,但是其 UID 会不同。</span></p>
  <p id="udaebc062" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">如果某物声称其生命期与某 Pod 相同,例如存储</span><a href="https://kubernetes.io/zh-cn/docs/concepts/storage/volumes/" data-href="https://kubernetes.io/zh-cn/docs/concepts/storage/volumes/" target="_blank" class="ne-link"><span class="ne-text">卷</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">, 这就意味着该对象在此 Pod (UID 亦相同)存在期间也一直存在。 如果 Pod 因为任何原因被删除,甚至某完全相同的替代 Pod 被创建时, 这个相关的对象(例如这里的卷)也会被删除并重建。</span></p>
  <p id="u54f82026" class="ne-p" style="text-align: left"><img src="https://cdn.nlark.com/yuque/0/2022/svg/29649025/1666802667072-8b4eeb04-0d54-45bd-9360-4e0591ada04e.svg" width="141" id="ucc72f7b1" class="ne-image" style="color: rgb(34, 34, 34); font-size: 16px"></p>
  <h4 id="yAyHF" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34)">Pod 结构图例</span></h4>
  <p id="uf588bee3" class="ne-p" style="text-align: left"><em><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">一个包含多个容器的 Pod 中包含一个用来拉取文件的程序和一个 Web 服务器, 均使用持久卷作为容器间共享的存储。</span></em></p>
  <h2 id="WeGYM" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34)">容器状态</span></h2>
  <p id="ud002ebac" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">Kubernetes 会跟踪 Pod 中每个容器的状态,就像它跟踪 Pod 总体上的</span><a href="https://kubernetes.io/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" data-href="https://kubernetes.io/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" target="_blank" class="ne-link"><span class="ne-text">阶段</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">一样。 你可以使用</span><a href="https://kubernetes.io/zh-cn/docs/concepts/containers/container-lifecycle-hooks/" data-href="https://kubernetes.io/zh-cn/docs/concepts/containers/container-lifecycle-hooks/" target="_blank" class="ne-link"><span class="ne-text">容器生命周期回调</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">来在容器生命周期中的特定时间点触发事件。</span></p>
  <p id="u7f46bed7" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">一旦</span><a href="https://kubernetes.io/zh-cn/docs/reference/command-line-tools-reference/kube-scheduler/" data-href="https://kubernetes.io/zh-cn/docs/reference/command-line-tools-reference/kube-scheduler/" target="_blank" class="ne-link"><span class="ne-text">调度器</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">将 Pod 分派给某个节点,</span><span class="ne-text" style="color: inherit; font-size: 14px">kubelet</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">就通过</span><a href="https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes" data-href="https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes" target="_blank" class="ne-link"><span class="ne-text">容器运行时</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">开始为 Pod 创建容器。容器的状态有三种:</span><span class="ne-text" style="color: inherit; font-size: 14px">Waiting</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">(等待)、</span><span class="ne-text" style="color: inherit; font-size: 14px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">(运行中)和</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">(已终止)。</span></p>
  <p id="ubb96d9f8" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">要检查 Pod 中容器的状态,你可以使用</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">kubectl describe pod &lt;pod 名称&gt;</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">。 其输出中包含 Pod 中每个容器的状态。</span></p>
  <p id="u4837537f" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">每种状态都有特定的含义:</span></p>
  <h3 id="uDqbR" style="text-align: left"><span class="ne-text" style="color: rgb(201, 115, 0); font-size: 22px">Waiting</span><span class="ne-text" style="color: rgb(34, 34, 34)"> </span><span class="ne-text" style="color: rgb(34, 34, 34)">(等待)</span></h3>
  <p id="ub67d3c60" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">如果容器并不处在</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">或</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态之一,它就处在</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Waiting</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态。 处于</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Waiting</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的容器仍在运行它完成启动所需要的操作:例如, 从某个容器镜像仓库拉取容器镜像,或者向容器应用</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><a href="https://kubernetes.io/zh-cn/docs/concepts/configuration/secret/" data-href="https://kubernetes.io/zh-cn/docs/concepts/configuration/secret/" target="_blank" class="ne-link"><span class="ne-text">Secret</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">数据等等。 当你使用</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">kubectl</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">来查询包含</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Waiting</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的容器的 Pod 时,你也会看到一个 Reason 字段,其中给出了容器处于等待状态的原因。</span></p>
  <h3 id="zXy4h" style="text-align: left"><span class="ne-text" style="color: rgb(201, 115, 0); font-size: 22px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34)">(运行中)</span></h3>
  <p id="uf2a37cff" class="ne-p" style="text-align: left"><span class="ne-text" style="color: inherit; font-size: 14px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态表明容器正在执行状态并且没有问题发生。 如果配置了</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">postStart</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">回调,那么该回调已经执行且已完成。 如果你使用</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">kubectl</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">来查询包含</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的容器的 Pod 时, 你也会看到关于容器进入</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Running</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的信息。</span></p>
  <h3 id="pReMC" style="text-align: left"><span class="ne-text" style="color: rgb(201, 115, 0); font-size: 22px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34)">(已终止)</span></h3>
  <p id="u6dca059b" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">处于</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的容器已经开始执行并且或者正常结束或者因为某些原因失败。 如果你使用</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">kubectl</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">来查询包含</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态的容器的 Pod 时, 你会看到容器进入此状态的原因、退出代码以及容器执行期间的起止时间。</span></p>
  <p id="u692386be" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">如果容器配置了</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">preStop</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">回调,则该回调会在容器进入</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">Terminated</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">状态之前执行。</span></p>
  <h2 id="OAACI" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34)">容器重启策略</span></h2>
  <p id="u3adf714d" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">Pod 的</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">spec</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">中包含一个</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">restartPolicy</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">字段,其可能取值包括 Always、OnFailure 和 Never。默认值是 Always。</span></p>
  <p id="u16b17b02" class="ne-p" style="text-align: left"><span class="ne-text" style="color: inherit; font-size: 14px">restartPolicy</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">适用于 Pod 中的所有容器。</span><span class="ne-text" style="color: inherit; font-size: 14px">restartPolicy</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">仅针对同一节点上</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: inherit; font-size: 14px">kubelet</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">的容器重启动作。当 Pod 中的容器退出时,</span><span class="ne-text" style="color: inherit; font-size: 14px">kubelet</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">会按指数回退方式计算重启的延迟(10s、20s、40s、...),其最长延迟为 5 分钟。 一旦某容器执行了 10 分钟并且没有出现问题,</span><span class="ne-text" style="color: inherit; font-size: 14px">kubelet</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">对该容器的重启回退计时器执行重置操作。</span></p>
  <h2 id="mHnS6" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34)">Pod 状况</span></h2>
  <p id="u170b181f" class="ne-p" style="text-align: left"><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">Pod 有一个 PodStatus 对象,其中包含一个</span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#podcondition-v1-core" data-href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#podcondition-v1-core" target="_blank" class="ne-link"><span class="ne-text">PodConditions</span></a><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px"> </span><span class="ne-text" style="color: rgb(34, 34, 34); font-size: 16px">数组。Pod 可能通过也可能未通过其中的一些状况测试。 Kubelet 管理以下 PodCondition:</span></p>
  <ul class="ne-ul">

标签:Terminated,容器,状态,Running,测试,Pod,节点
From: https://www.cnblogs.com/yutoujun/p/16914327.html

相关文章

  • LIN休眠唤醒及测试心得
    前言  上期LIN测试小课堂,我们分享了LIN总线帧结构及各场干扰,如何测试样件是否不响应错误的帧结构。 这次我们的介绍主题是LIN休眠唤醒,一起看看标准和差异性,开发和......
  • 迅为IMX8M开发板2gst-inspect-1.0测试
    gstreamer开发中,一般开发思路为:寻找命令行实现--命令行验证--将命令行集成到代码中---代码工程化。当然如果你要代码更优雅一点,可以用命令行用对应的API来实现。本节来......
  • 单元测试中常见错误
    单元测试中常见错误单元的常见错误一般出现在5个方面:代码的稳定、易读、规范、易维护、专业。因此,单元测试的关注的重点有5点:单元接口、局部数据结构、边界条件......
  • Note.js框架中的cluster集群和断言测试的实战剖析
    Cluster节点。Js在单个线程中运行单个实例。为了使用当前的多核系统,用户(开发人员)有时会使用一个Node字符串。js进程来处理加载任务。集群模块允许轻松创建共享服务器端口......
  • 分层测试
              ......
  • api渗透测试
    总体分为两个大块,信息收集和渗透测试两部分,大概整理了400个测试点    #转载大佬的文章信息收集一.识别架构1.架构识别   2.文档    二.检查文档......
  • Apifox:成熟的测试工具要学会自己写接口文档
    好家伙, 在开发过程中,我们总是避免不了进行接口的测试,而相比手动敲测试代码,使用测试工具进行测试更为便捷,高效 今天发现了一个非常好用的接口测试工具Apifox相比于P......
  • DTOJ 2022-11-21 测试 题解
    测试成果非常寄35+56+0+8=99基本上把能犯的错误都犯了T1记得dp数组初始化\(-\infty\)!!!!T2记得认真暴搜,不要乱记录访问状态T3记得把调试删掉!!!!!T4记得开longlong......
  • 渗透测试实用手册
    1. SQL注入漏洞漏洞名称SQL注入漏洞漏洞地址 漏洞等级高危漏洞描述SQL注入是开发者对用户输入的参数过滤不严格,通过把SQL命令插入到Web......
  • Java 反射测试
    importjava.lang.reflect.InvocationTargetException;importjava.lang.reflect.Method;/***Java反射测试**@authorAdministrator**/publicclassR......