KubePodInventory 表的查询

有关在 Azure 门户中使用这些查询的信息,请参阅 Log Analytics 教程。 有关 REST API,请参阅查询

崩溃循环中的 Pod

确定 Pod/容器是否有崩溃循环阶段。

//Determines whether Pods/Containers has Crash-Loop phase
KubePodInventory
| where ContainerStatus  == 'waiting' 
| where ContainerStatusReason == 'CrashLoopBackOff' or ContainerStatusReason == 'Error'
| extend ContainerLastStatus=todynamic(ContainerLastStatus)
| summarize RestartCount = arg_max(ContainerRestartCount, Computer, Namespace, ContainerLastStatus.reason) by Name

处于挂起状态的 Pod

检查无法启动的 Pod 及其挂起时间。

//Check Pods that cannot be started and its pending time
KubePodInventory
| where PodStatus == 'Pending'
| project PodCreationTimeStamp, Namespace, PodStartTime, PodStatus, Name, ContainerStatus
| summarize Start = any(PodCreationTimeStamp), arg_max(PodStartTime, Namespace) by Name
| extend PodStartTime = iff(isnull(PodStartTime), now(), PodStartTime)
| extend PendingTime = PodStartTime - Start
| project Name, Namespace ,PendingTime

在 KubePodInventory 中查找

在 KubePodInventory 中查找以在 KubePodInventory 表中搜索特定值。/n请注意,此查询需要更新 <SeachValue> 参数,才能生成结果

// This query requires a parameter to run. Enter value in SearchValue to find in table.
let SearchValue =  "<SearchValue>";//Please update term you would like to find in the table.
KubePodInventory
| where * contains tostring(SearchValue)
| take 1000