我想知道在Kubernetes中启动我的pod所需的时间。我的pod有3 Init Containers
和9 actual Containers
。以下是我到目前为止所尝试的:
****方法1:***启动pod并监控,直到有9/9个容器正在运行。kubectl describe pod <pod_name>
中的AGE
将给予启动时间的概念。
****方法2:***使用kubectl events
或kubectl describe
命令参考pod的事件。问题是并非所有容器都有事件。此外,没有明确的方法来了解pod处于READY
状态所用的时间。
**问题:**Kubernetes是否提供任何方法来确定整个pod启动时间?
4条答案
按热度按时间dsekswqp1#
随着 设置 的 开始 , 您 的 Pod 将 经历 一 系列 PodConditions 。
您 可以 使用 :
中 的 每 一 个
观察 这些 不同 条件 下 的 进展 :
格式
如果 您 希望 在 shell 中 自动 解析 所有 这些 内容 , 我 建议 使用
yq
进行 实际 的 YAML 解析 。1aaf6o9v2#
虽然 在 Kubernetes 中 没有 确切 的 机制 , 但 您 可能 需要 检查 Kube-state - metrics :
kube-state - metrics 是 一 个 简单 的 服务 , 用于 监听 Kubernetes API 服务 器 并 生成 有关 对象 状态 的 指标 。 ( 请 参阅 下面 " 指标 " 部分 中 的 示例 。 ) 它 并 不 关注 单个 Kubernetes 组件 的 运行 状况 , 而是 关注 内部 各种 对象 的 运行 状况 , 如 部署 、 节点 和 pod 。
使用 它 可以 导出 对象 创建 时间 。 在 这种 情况 下 , 度量 名称 将 是
kube_<OBJECT>_created
。 第 6 节 中 的 article 关于 度量 解释 了 更多 关于 kube 状态 度量 和 对象 创建 时间 的 使用 。请 注意 , 如果 您 要 测量
pod start time
, 您 必须 假设 运行 该 单元 所 需 的 所有 映像 都 已 预 拉 到 计算机 上 。 否则 , 您 的 测量 结果 将 不 正确 , 因为 它 将 包含 影响 Kubernetes 性能 的 变量 , 如 网络 或 映像 大小 。ssm49v7z3#
如果这对任何人都有帮助,这里有一个使用kubectl、yq和bash的示例
ukxgm1gy4#
基于 Jedi 的 答案 , 我 编写 了 下面 的 工具 , 使用 https://stedolan.github.io/jq/ 来 实现 这 一 点 。 我 这样 运行 它 :x1月 1 日
中 的 每 一 个