AKS Container Insights: How to list not ready pods?

5/21/2021

I'm using Azure Container Insights for an AKS cluster and want to filter some logs using Log Analytics and Kusto Query Language. I do it to provide a convenient dashboard and alerts.

What I'm trying to achieve is list only not ready pods. Listing the ones not Running is not enough. This can be easily filtered using kubectl e.g. following this post https://stackoverflow.com/questions/58992774/how-to-get-list-of-pods-which-are-ready However this data is not avaiable when querying in Log analytics with Kusto as the containerStatuses seems to be only a string enter image description here

It should be somehow possible because Container Insights allow this filtering in Metrics section. However it's not fully satisfying because with metrics my filtering capabilities are much smaller.

-- Tomasz Chudzik
azure
azure-aks
azure-application-insights
azure-monitoring
kubernetes

2 Answers

6/9/2021

The efdestegul's answer was only listing not "Running" pods and I was looking for not ready ones. However this answer led me to a query which I actually needed and thank you for that. Maybe this will help others.

let timeGrain=1m;

KubePodInventory
// | where Namespace in ('my-namespace-1', 'my-namespace-2')
| summarize countif(ContainerStatus == 'waiting') by bin(TimeGenerated,timeGrain)
| order by countif_ desc
| render timechart

With this query I'm able to render a chart that displays all not ready pods in time. And actually in a very useful way, only the pods that were not ready for more than expected and they needed to be restarted. You can always filter your results for any namespaces you need.

-- Tomasz Chudzik
Source: StackOverflow

5/31/2021

You can do it for pods as below for last 1h.

let endDateTime = now();
let startDateTime = ago(1h);
 
KubePodInventory
| where TimeGenerated < endDateTime
| where TimeGenerated >= startDateTime
| where PodStatus != "Running"
| distinct Computer, PodUid, TimeGenerated, PodStatus
-- efdestegul
Source: StackOverflow