Stage 5 · Platform
Azure Monitor & Observability
AKS Monitoring with Container Insights
Node/pod metrics, KEDA scaling metrics, and multi-cluster views.
Container Insights Overview
Container Insights is a feature of Azure Monitor that collects performance metrics, container logs, and inventory data from AKS clusters. It provides a pre-built monitoring experience with maps, metrics explorer, and analytics queries.
# Enable during cluster creation
az aks create \
--resource-group rg-aks-prod \
--name aks-payments-prod \
--enable-addons monitoring \
--workspace-resource-id "/subscriptions/{sub-id}/resourceGroups/rg-monitoring/providers/Microsoft.OperationalInsights/workspaces/law-aks" \
--node-count 3
# Enable on existing cluster
az aks enable-addons \
--resource-group rg-aks-prod \
--name aks-payments-prod \
--addons monitoring \
--workspace-resource-id "/subscriptions/{sub-id}/resourceGroups/rg-monitoring/providers/Microsoft.OperationalInsights/workspaces/law-aks"Container Insights installs a DaemonSet (one pod per node) that collects metrics and logs. The data flows to the specified Log Analytics workspace.
Node Metrics
// Node CPU and memory usage over time
InsightsMetrics
| where TimeGenerated > ago(1h)
| where Namespace == "K8SNode"
| where Name in ("cpuUsagePercentage", "memoryWorkingSetPercentage")
| summarize avg(Val) by Computer, Name, bin(TimeGenerated, 5m)
| render timechart
// Node with highest CPU
InsightsMetrics
| where TimeGenerated > ago(5m)
| where Namespace == "K8SNode"
| where Name == "cpuUsagePercentage"
| top 5 by Val desc
| project Computer, NodeCPU = ValInsightsMetrics is the table populated by Container Insights. Namespace identifies the metric source (K8SNode, K8SContainer, K8SPod).
Pod and Container Metrics
// Top 10 pods by CPU usage
InsightsMetrics
| where TimeGenerated > ago(5m)
| where Namespace == "K8SContainer"
| where Name == "cpuUsagePercentage"
| top 10 by Val desc
| project Pod = Computer, Container = InstanceName, CPU = Val
// Pods exceeding memory limits
InsightsMetrics
| where TimeGenerated > ago(5m)
| where Namespace == "K8SContainer"
| where Name == "memoryRSS"
| where Val > 0
| join kind=leftouter (
KubePodInventory
| project PodName, Namespace, MemoryLimit
) on PodName, Namespace
| where MemoryLimit > 0 and Val > MemoryLimit * 0.9
| project Pod = PodName, Namespace, MemoryMB = Val / 1024 / 1024, LimitMB = MemoryLimit / 1024 / 1024KubePodInventory provides Kubernetes metadata (labels, status, owner) that you can join with InsightsMetrics for rich pod-level analysis.
Container Insights includes a pre-built Azure Monitor Workbook with node health, pod status, and resource consumption charts. Navigate to your AKS cluster in the Portal and click 'Insights'.
Container Logs
// All logs from a specific pod
ContainerLogV2
| where TimeGenerated > ago(1h)
| where PodName == "payments-api-7d4b8c6f5-2xk9j"
| project TimeGenerated, LogEntry
// Error logs across all pods
ContainerLogV2
| where TimeGenerated > ago(24h)
| where LogEntry contains "ERROR"
| summarize count() by PodName, Namespace
| order by count_ desc
// Logs from a specific container in a pod
ContainerLogV2
| where TimeGenerated > ago(1h)
| where PodName startswith "payments"
| where ContainerName == "payments"
| where LogEntry contains "exception"
| project TimeGenerated, LogEntryContainerLogV2 provides structured container logs with PodName, ContainerName, and Namespace fields. Use LogEntry for the actual log message.
KEDA Scaling Metrics
KEDA (Kubernetes Event-Driven Autoscaler) publishes custom metrics for pod autoscaling. These metrics appear in Container Insights and can trigger HPA scaling.
// View KEDA scaler metrics
InsightsMetrics
| where TimeGenerated > ago(1h)
| where Namespace == "keda"
| where Name == "scaler_active"
| summarize avg(Val) by Tag, bin(TimeGenerated, 1m)
| render timechart
// Current queue length for scaled objects
InsightsMetrics
| where TimeGenerated > ago(5m)
| where Namespace == "keda"
| where Name == "scaler_metrics_value"
| project TimeGenerated, Metric = Tag, Value = ValKEDA metrics are published to the Kubernetes metrics API. Container Insights captures them automatically when installed.
Multi-Cluster Monitoring
When running multiple AKS clusters (dev, staging, prod, or multi-region), you need a unified monitoring view. Use a single Log Analytics workspace to aggregate data from all clusters.
// Compare CPU across all clusters
InsightsMetrics
| where TimeGenerated > ago(5m)
| where Namespace == "K8SNode"
| where Name == "cpuUsagePercentage"
| summarize avgCPU = avg(Val) by Computer
| order by avgCPU desc
// Aggregate pod restarts across clusters
ContainerInsights
| where TimeGenerated > ago(24h)
| where PodRestartCount > 0
| summarize maxRestarts = max(PodRestartCount) by ClusterId, Namespace, PodName
| order by maxRestarts descThe ClusterId field identifies which cluster a metric came from. Use it to filter or group data across your fleet of clusters.
Point all AKS clusters to the same Log Analytics workspace. This enables cross-cluster queries, unified alerting, and a single pane of glass for your container fleet.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.