|
| 1 | +--- |
| 2 | +title: Monitor control plane metrics |
| 3 | +description: Learn how to enable and query control plane metrics from AKS on Azure Local 23H2. |
| 4 | +ms.date: 03/26/2025 |
| 5 | +ms.topic: how-to |
| 6 | +author: sethmanheim |
| 7 | +ms.author: sethm |
| 8 | +ms.reviewer: haojiehang |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +# Monitor control plane metrics |
| 13 | + |
| 14 | +[!INCLUDE [hci-applies-to-23h2](includes/hci-applies-to-23h2.md)] |
| 15 | + |
| 16 | +This article describes how to enable and query control plane metrics from AKS on Azure Local 23H2. The workflow is as follows: |
| 17 | + |
| 18 | +- Enable Managed Prometheus extension |
| 19 | +- Enable control plane metrics |
| 20 | +- (Optional) view metrics in Grafana |
| 21 | + |
| 22 | +Control plane metrics provide critical visibility into the availability and performance of Kubernetes control plane components, such as the API server, scheduler, or controller manager. You can use these metrics to maximize observability and maintain operational excellence for your cluster. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +Before you begin, make sure the following prerequisites are met: |
| 27 | + |
| 28 | +- A running AKS on Azure Local instance. |
| 29 | +- Install the latest version of the **aksarc**, **connectedk8s**, and **k8s-extension** CLI extensions. |
| 30 | +- [Download and install **kubectl**](https://kubernetes.io/docs/tasks/tools/) on your development machine. |
| 31 | +- [Understand the basics of Prometheus Query Language](https://prometheus.io/docs/prometheus/latest/querying/examples/). |
| 32 | +- [Understand the basics of Kubernetes system component metrics](https://kubernetes.io/docs/concepts/cluster-administration/system-metrics/). |
| 33 | + |
| 34 | +## Enable Managed Prometheus extension |
| 35 | + |
| 36 | +Azure Monitor collects and aggregates important metrics from your AKS Arc running on Azure Local instance. In addition to [platform metrics](kubernetes-monitor-metrics.md#metrics) collected from your cluster, you can view granular Kubernetes metrics using the managed Prometheus extension. This extension collects Prometheus metrics from your deployment and stores them in an Azure Monitor workspace in Azure. Once they are ingested, you can analyze them in Metrics Explorer or use prebuilt dashboards in Azure Managed Grafana. |
| 37 | + |
| 38 | +### Step 1: Install the managed Prometheus extension |
| 39 | + |
| 40 | +You can install the extension either from the Azure portal, or using CLI. |
| 41 | + |
| 42 | +# [Azure portal](#tab/azureportal) |
| 43 | + |
| 44 | +Go to your Kubernetes instance, then select **Monitoring > Insights > Monitor Settings**: |
| 45 | + |
| 46 | +:::image type="content" source="media/control-plane-metrics/monitor-settings.png" alt-text="Screenshot of portal showing monitor settings." lightbox="media/control-plane-metrics/monitor-settings.png"::: |
| 47 | + |
| 48 | +#### [Azure CLI](#tab/azurecli) |
| 49 | + |
| 50 | +The following command installs the managed Prometheus extension with a default Azure Monitor workspace: |
| 51 | + |
| 52 | +```azurecli |
| 53 | +az k8s-extension create --name azuremonitor-metrics --cluster-name <cluster-name> --resource-group <resource-group> --cluster-type connectedClusters --extension-type Microsoft.AzureMonitor.Containers.Metrics |
| 54 | +``` |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +See the [guidance for the managed Prometheus extension onboarding](/azure/azure-monitor/containers/kubernetes-monitoring-enable?tabs=cli#enable-prometheus-and-grafana). |
| 59 | + |
| 60 | +### Step 2: Verify extension and metrics pod deployment |
| 61 | + |
| 62 | +To verify the extension installation, you can run `az connectedk8s proxy` to connect to the cluster and use **kubectl** to list the metrics pods. The pods should start with the name **ama-metrics-** and are in a running state. |
| 63 | + |
| 64 | +```azurecli |
| 65 | +kubectl get pods -n kube-system |
| 66 | +``` |
| 67 | + |
| 68 | +The output of the command is similar to the following: |
| 69 | + |
| 70 | +```output |
| 71 | +NAME READY STATUS RESTARTS AGE |
| 72 | +akshci-telemetry-5df56fd5-s5wtm 1/1 Running 1 (37h ago) 44d |
| 73 | +ama-logs-nqf9h 3/3 Running 0 5h29m |
| 74 | +ama-logs-pvvb2 3/3 Running 2 (5h21m ago) 5h29m |
| 75 | +ama-logs-rs-86bc9dd898-4p7pv 2/2 Running 0 5h29m |
| 76 | +**ama-metrics-98bb54876-dndrh** 2/2 Running 2 (3h33m ago) 5h30m |
| 77 | +**ama-metrics-ksm-6544c98f5f-ph6sp** 1/1 Running 0 5h30m |
| 78 | +**ama-metrics-node-6dl7p** 2/2 Running 2 (3h33m ago) 5h30m |
| 79 | +**ama-metrics-node-ztwzt** 2/2 Running 1 (3h33m ago) 5h30m |
| 80 | +…. |
| 81 | +``` |
| 82 | + |
| 83 | +## Enable control plane metrics with custom configuration |
| 84 | + |
| 85 | +After you enable the extension, you can view Prometheus Metrics from [targets scraped by default](/azure/azure-monitor/containers/prometheus-metrics-scrape-default#targets-scraped-by-default) in the Azure Monitor workspace. The [default ON targets](/azure/azure-monitor/containers/prometheus-metrics-scrape-configuration-minimal#minimal-ingestion-for-default-on-targets) include kubelet, kube-state-metrics, node-exporter, etc. To get started with kubelet metrics, use the PromQL below: |
| 86 | + |
| 87 | +```bash |
| 88 | +kubelet_running_pods{cluster="<cluster_name>", instance="<instance_name>", job="kubelet"} |
| 89 | +``` |
| 90 | + |
| 91 | +:::image type="content" source="media/control-plane-metrics/metrics.png" alt-text="Screenshot showing metrics query." lightbox="media/control-plane-metrics/metrics.png"::: |
| 92 | + |
| 93 | +To view control plane metrics such as APIServer and ETCD, you can customize the scraping of Prometheus metrics by applying the config maps to your cluster. The metrics pods pick up the config maps and pods restart in 2-3 minutes. Follow these steps to enable. |
| 94 | + |
| 95 | +### Step 1: connect to Kubernetes |
| 96 | + |
| 97 | +Connect to your cluster using `az connectedk8s proxy` and run `kubectl get pods -A` to make sure you're connected. |
| 98 | + |
| 99 | +### Step 2: download the configuration files and review the content |
| 100 | + |
| 101 | +Managed Prometheus uses an [agent-based solution](https://github.com/Azure/prometheus-collector) to collect Prometheus metrics and send them to the Azure Monitor workspace. There are two configuration files to download and review: **ama-metrics-settings-configmap.yaml** and **ama-metrics-prometheus-config-configmap.yaml**. For more information about customizing metrics scraping using configuration files, see [Customize scraping of Prometheus metrics](/azure/azure-monitor/containers/prometheus-metrics-scrape-configuration). |
| 102 | + |
| 103 | +- To enable **APIServer** metrics, modify the value of `apiserver` under the default OFF targets and set it to **true** in **ama-metrics-settings-configmap.yaml**. For the list of metrics, see [minimal ingestion for default OFF targets](/azure/azure-monitor/containers/prometheus-metrics-scrape-configuration-minimal#minimal-ingestion-for-default-off-targets). |
| 104 | +- To enable metrics from components not listed under default OFF targets such as **ETCD, Controller Manager, Kube Scheduler**, add a new scraping job in **ama-metrics-prometheus-config-configmap.yaml**. |
| 105 | + |
| 106 | +[You can download](https://github.com/Azure/aksArc/tree/main/scripts/ControlPlaneMetrics) these two configuration files to your local machine and review the content before going to the next step. |
| 107 | + |
| 108 | +### Step 3: apply custom configuration files |
| 109 | + |
| 110 | +Run the following commands to apply the changes, then wait several minutes for the metrics pods to restart. |
| 111 | + |
| 112 | +```bash |
| 113 | +kubectl apply -f ama-metrics-settings-configmap.yaml |
| 114 | +kubectl apply -f ama-metrics-prometheus-config-configmap.yaml |
| 115 | +``` |
| 116 | + |
| 117 | +### Step 4: query metrics in Azure Monitor workspace |
| 118 | + |
| 119 | +Go to the linked **Azure Monitor Workspace > Metric Explorer** and use PromQL to validate that the metrics are ingested. In the following sample query, it shows a stable kube-scheduler metrics `scheduler_schedule_attempts_total` from a specific Kubernetes cluster. |
| 120 | + |
| 121 | +:::image type="content" source="media/control-plane-metrics/metrics-ingested.png" alt-text="Screenshot of portal showing metrics ingestion." lightbox="media/control-plane-metrics/metrics-ingested.png"::: |
| 122 | + |
| 123 | +## View metrics in Grafana |
| 124 | + |
| 125 | +Metrics Explorer is convenient for metrics validation. To operationalize Kubernetes monitoring with Azure Monitor, it's recommended that you monitor the metrics using Azure Managed Grafana. |
| 126 | + |
| 127 | +### Step 1: install Azure Managed Grafana |
| 128 | + |
| 129 | +[Follow these instructions](/azure/managed-grafana/how-to-connect-azure-monitor-workspace) to create a Grafana workspace, link to an Azure Monitor workspace, and view the metrics in Grafana dashboards. You can view the dashboard under **Monitoring > Insights > Monitor Settings**. Multiple instances can be linked to the same Azure Monitor workspace, so make sure to choose the right dashboard. |
| 130 | + |
| 131 | +### Step 2: import a prebuilt dashboard for control plane metrics |
| 132 | + |
| 133 | +[Download the API server dashboard ](https://grafana.com/grafana/dashboards/20331-kubernetes-api-server/) to your local machine, copy the JSON content, then import it to the managed Grafana dashboard. |
| 134 | + |
| 135 | +:::image type="content" source="media/control-plane-metrics/dashboards.png" alt-text="Screenshot showing metrics dashboard." lightbox="media/control-plane-metrics/dashboards.png"::: |
| 136 | + |
| 137 | +### Step 3: view metrics in the dashboard |
| 138 | + |
| 139 | +Ensure that the data source and cluster names are correct. You can view the metrics in Grafana and customize them as needed. |
| 140 | + |
| 141 | +:::image type="content" source="media/control-plane-metrics/metrics-status.png" alt-text="Screenshot showing control plane metrics status." lightbox="media/control-plane-metrics/metrics-status.png"::: |
| 142 | + |
| 143 | +## Next steps |
| 144 | + |
| 145 | +- [AKS Arc monitoring data reference](kubernetes-monitor-metrics.md) |
| 146 | +- [Prometheus scrape configuration](/azure/azure-monitor/containers/prometheus-metrics-scrape-configuration) |
0 commit comments