0
0
Azurecloud~5 mins

AKS monitoring with Container Insights in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Monitoring your Azure Kubernetes Service (AKS) cluster helps you see how your apps and infrastructure are doing. Container Insights collects data about your containers and nodes so you can find and fix problems quickly.
When you want to track the health and performance of your AKS cluster in real time.
When you need to see logs and metrics from your containers to troubleshoot issues.
When you want to get alerts if your AKS cluster has problems like high CPU or memory use.
When you want to understand resource usage to optimize costs in your AKS environment.
When you want to visualize your container workloads and their status in Azure Monitor.
Commands
This command enables Container Insights monitoring addon on your AKS cluster to start collecting logs and metrics.
Terminal
az aks enable-addons --resource-group example-resource-group --name example-aks-cluster --addons monitoring
Expected OutputExpected
Addon monitoring is enabled for cluster example-aks-cluster in resource group example-resource-group.
--resource-group - Specifies the resource group where your AKS cluster is located.
--name - Specifies the name of your AKS cluster.
--addons - Specifies which addon to enable, here it is monitoring for Container Insights.
This command checks if the monitoring addon is enabled on your AKS cluster.
Terminal
az aks show --resource-group example-resource-group --name example-aks-cluster --query addonProfiles.omsagent.enabled
Expected OutputExpected
true
--query - Filters the output to show only the monitoring addon status.
This command shows details of the Log Analytics workspace where Container Insights sends monitoring data.
Terminal
az monitor log-analytics workspace show --resource-group example-resource-group --workspace-name example-workspace
Expected OutputExpected
{ "customerId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "location": "eastus", "name": "example-workspace", "resourceGroup": "example-resource-group", "sku": { "name": "PerGB2018" }, "type": "Microsoft.OperationalInsights/workspaces" }
--workspace-name - Specifies the name of the Log Analytics workspace.
This command downloads the cluster credentials so you can use kubectl to interact with your AKS cluster.
Terminal
az aks get-credentials --resource-group example-resource-group --name example-aks-cluster
Expected OutputExpected
Merged "example-aks-cluster" as current context in /home/user/.kube/config
This command lists the monitoring agent pods running in the kube-system namespace to verify Container Insights agents are active.
Terminal
kubectl get pods -n kube-system -l app=omsagent
Expected OutputExpected
NAME READY STATUS RESTARTS AGE omsagent-abcde 1/1 Running 0 10m omsagent-fghij 1/1 Running 0 10m
-n - Specifies the namespace to look in, here kube-system where monitoring agents run.
-l - Filters pods by label, here to find omsagent pods.
Key Concept

If you remember nothing else from this pattern, remember: enabling the monitoring addon on AKS automatically sets up Container Insights to collect and send your cluster's health and performance data to Azure Monitor.

Common Mistakes
Trying to enable monitoring addon on a non-existent AKS cluster.
The command fails because the cluster name or resource group is incorrect or the cluster does not exist.
Verify the AKS cluster name and resource group with 'az aks list' before enabling addons.
Not checking if the monitoring addon is enabled after running the enable command.
You might think monitoring is active but it is not, so you won't get logs or metrics.
Always run 'az aks show' with query to confirm the monitoring addon is enabled.
Not having kubectl configured with cluster credentials before checking monitoring pods.
kubectl commands will fail or show no pods if credentials are missing.
Run 'az aks get-credentials' to configure kubectl before querying pods.
Summary
Enable Container Insights monitoring addon on your AKS cluster using Azure CLI.
Verify the monitoring addon is enabled to ensure data collection is active.
Check the Log Analytics workspace where monitoring data is sent.
Download cluster credentials to use kubectl for inspecting monitoring agent pods.
Confirm monitoring agents are running in the kube-system namespace.