Kubernetes 如何跟踪播客等待启动的时间?
我想了解POD何时处于挂起状态,因为它们无法安排所需的资源。是否有方法跟踪POD在“挂起”或“计划”状态下花费的时间?目前还没有其他答案……因此,我们开始:Kubernetes 如何跟踪播客等待启动的时间?,kubernetes,Kubernetes,我想了解POD何时处于挂起状态,因为它们无法安排所需的资源。是否有方法跟踪POD在“挂起”或“计划”状态下花费的时间?目前还没有其他答案……因此,我们开始: kubectl -n <namespace> get events --sort-by=.metadata.creationTimestamp kubectl-n获取事件--sort by=.metadata.creationTimestamp …将列出按时间戳排序的事件(根据需要替换) 对于具体pod,这将输出以逗号分隔的
kubectl -n <namespace> get events --sort-by=.metadata.creationTimestamp
kubectl-n获取事件--sort by=.metadata.creationTimestamp
…将列出按时间戳排序的事件(根据需要替换
)
对于具体pod,这将输出以逗号分隔的状态更改列表及其时间戳:
kubectl -n <namespace> get po/<pod-name> -o jsonpath="{range .status.conditions[*]}{.type}{','}{.lastTransitionTime}{'\n'}{end}"
kubectl-n get po/-o jsonpath=“{range.status.conditions[*]}{.type}{,'}{.lastTransitionTime}{'\n'}{end}”
考虑到这些,再加上一点脚本编写,应该可以导出您要查找的信息。目前还没有其他答案……所以我们开始:
kubectl -n <namespace> get events --sort-by=.metadata.creationTimestamp
kubectl-n获取事件--sort by=.metadata.creationTimestamp
…将列出按时间戳排序的事件(根据需要替换
)
对于具体pod,这将输出以逗号分隔的状态更改列表及其时间戳:
kubectl -n <namespace> get po/<pod-name> -o jsonpath="{range .status.conditions[*]}{.type}{','}{.lastTransitionTime}{'\n'}{end}"
kubectl-n get po/-o jsonpath=“{range.status.conditions[*]}{.type}{,'}{.lastTransitionTime}{'\n'}{end}”
考虑到这些,再加上一些脚本,应该可以导出您要查找的信息。
状态下的lastTransitionTime
。pod清单中的conditions字段显示pod达到运行状态之前的每个中间状态的时间戳
pod转换的时间戳如下<代码>初始化->准备->集装箱准备->pod计划:
$ kubectl get pod coredns-fb8b8dccf-2lhl4 -n=kube-system -o json | jq '.status.conditions'
[
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:17Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:56Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:56Z",
"status": "True",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:17Z",
"status": "True",
"type": "PodScheduled"
}
]
pod初始化后,通常处于
Pending
状态,直到它被调度为止(PodScheduled
状态)并达到运行状态。状态下的lastTransitionTime
。pod清单中的条件
字段显示pod达到运行状态之前的每个中间状态的时间戳
pod转换的时间戳如下<代码>初始化->准备->集装箱准备->pod计划:
$ kubectl get pod coredns-fb8b8dccf-2lhl4 -n=kube-system -o json | jq '.status.conditions'
[
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:17Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:56Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:56Z",
"status": "True",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-07-22T19:58:17Z",
"status": "True",
"type": "PodScheduled"
}
]
pod初始化后,通常处于
Pending
状态,直到它被调度(PodScheduled
以上状态)并达到Running
状态。要显示所有pod-也处于永久“Pending”状态,您可以使用:
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\t"}{.status.startTime}{"\n"}{end}'
kubectl get pods --all-namespaces -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,STATE:status.containerStatuses[*].state.waiting.reason,PHASE:status.phase
资源:
- ,
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\t"}{.status.startTime}{"\n"}{end}'
kubectl get pods --all-namespaces -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,STATE:status.containerStatuses[*].state.waiting.reason,PHASE:status.phase
资源:
- ,
kubectl descripe pods
,您可以看到这些pods的年龄和原因,或者直接在kubectl get pods
中,您可以注意到状态和年龄。因此,我有一个python脚本,它可以获取处于“挂起”状态所经过的时间。然而,我被时间戳弄糊涂了。对我来说,“初始化”状态的时间戳比“Pod计划”的时间戳大('Initialized',datetime.datetime(2019,7,24,16,26,56,tzinfo=tzutc())('PodScheduled',datetime.datetime(2019,7,24,16,26,18,tzinfo=tzutc())-38。“挂起”中的条件是否按照您提到的顺序进行,即初始化->准备->集装箱准备->PodScheduled?我猜您在回复中提到的转换顺序不太正确..在阅读说明()时,我认为计划应该是第一件事…然后初始化…然后是ContainerReady或Ready…仍然不确定应该使用哪两个时间戳来计算“挂起”的时间…我同意你的看法。您应该在事件下使用kubectl descripe pods
,您可以看到这些pods的年龄和原因,或者直接在kubectl get pods
中注意状态和年龄。