|
| 1 | +--- |
| 2 | +title: Monitor the ingress-nginx controller metrics in the application routing add-on with Prometheus (preview) |
| 3 | +description: Configure Prometheus to scrape the ingress-nginx controller metrics. |
| 4 | +ms.service: azure-kubernetes-service |
| 5 | +ms.subservice: aks-networking |
| 6 | +ms.custom: devx-track-azurecli |
| 7 | +author: sabbour |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 07/12/2023 |
| 10 | +ms.author: asabbour |
| 11 | +--- |
| 12 | + |
| 13 | +# Monitor the ingress-nginx controller metrics in the application routing add-on with Prometheus in Grafana (preview) |
| 14 | + |
| 15 | +The ingress-nginx controller in the application routing add-on exposes many metrics for requests, the nginx process, and the controller that can be helpful in analyzing the performance and usage of your application. |
| 16 | + |
| 17 | +The application routing add-on exposes the Prometheus metrics endpoint at `/metrics` on port 10254. |
| 18 | + |
| 19 | +[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)] |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +- An Azure Kubernetes Service (AKS) cluster with the [application routing add-on enabled][app-routing]. |
| 24 | +- A Prometheus instance, such as [Azure Monitor managed service for Prometheus][managed-prometheus-configure]. |
| 25 | +- A Grafana instance, such as [Azure Managed Grafana][managed-grafana]. |
| 26 | + |
| 27 | +## Validating the metrics endpoint |
| 28 | + |
| 29 | +To validate the metrics are being collected, you can set up a port forward to one of the ingress-nginx controller pods. |
| 30 | + |
| 31 | +```bash |
| 32 | +kubectl get pods -n app-routing-system |
| 33 | +``` |
| 34 | + |
| 35 | +```bash |
| 36 | +NAME READY STATUS RESTARTS AGE |
| 37 | +external-dns-667d54c44b-jmsxm 1/1 Running 0 4d6h |
| 38 | +nginx-657bb8cdcf-qllmx 1/1 Running 0 4d6h |
| 39 | +nginx-657bb8cdcf-wgcr7 1/1 Running 0 4d6h |
| 40 | +``` |
| 41 | + |
| 42 | +Now forward a local port to port 10254 on one of the nginx pods. |
| 43 | + |
| 44 | +```bash |
| 45 | +kubectl port-forward nginx-657bb8cdcf-qllmx -n app-routing-system :10254 |
| 46 | +``` |
| 47 | + |
| 48 | +```bash |
| 49 | +Forwarding from 127.0.0.1:43307 -> 10254 |
| 50 | +Forwarding from [::1]:43307 -> 10254 |
| 51 | +``` |
| 52 | + |
| 53 | +Note the local port (`43307` in this case) and open http://localhost:43307/metrics in your browser. You should see the ingress-nginx controller metrics loading. |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +You can now terminate the `port-forward` process to close the forwarding. |
| 58 | + |
| 59 | +## Configuring Azure Monitor managed service for Prometheus and Azure Managed Grafana using Container Insights |
| 60 | + |
| 61 | +Azure Monitor managed service for Prometheus is a fully managed Prometheus-compatible service that supports industry standard features such as PromQL, Grafana dashboards, and Prometheus alerts. This service requires configuring the metrics addon for the Azure Monitor agent, which sends data to Prometheus. If your cluster isn't configured with the add-on, you can follow this article to [configure your Azure Kubernetes Service (AKS) cluster to send data to Azure Monitor managed service for Prometheus][managed-prometheus-configure] and send the collected metrics to [an Azure Managed Grafana instance][create-grafana]. |
| 62 | + |
| 63 | +### Enable pod annotation based scraping |
| 64 | + |
| 65 | +Once your cluster is updated with the Azure Monitor agent, you need to configure the agent to enable scraping based on Pod annotations, which are added to the ingress-nginx pods. One way to set this setting is in the [`ama-metrics-settings-configmap`](https://aka.ms/azureprometheus-addon-settings-configmap) ConfigMap in the `kube-system` namespace. |
| 66 | + |
| 67 | +> [!CAUTION] |
| 68 | +> This will replace your existing `ama-metrics-settings-configmap` ConfigMap in the `kube-system`. If you already have a configuration, you may want to take a backup or merge it with this configuration. |
| 69 | +> |
| 70 | +> You can backup an existing `ama-metrics-settings-config` ConfigMap if it exists by running `kubectl get configmap ama-metrics-settings-configmap -n kube-system -o yaml > ama-metrics-settings-configmap-backup.yaml` |
| 71 | +
|
| 72 | +The following configuration sets the `podannotationnamespaceregex` parameter to `.*` to scrape all namespaces. |
| 73 | + |
| 74 | +```bash |
| 75 | +kubectl apply -f - <<EOF |
| 76 | +kind: ConfigMap |
| 77 | +apiVersion: v1 |
| 78 | +metadata: |
| 79 | + name: ama-metrics-settings-configmap |
| 80 | + namespace: kube-system |
| 81 | +data: |
| 82 | + schema-version: |
| 83 | + #string.used by agent to parse config. supported versions are {v1}. Configs with other schema versions will be rejected by the agent. |
| 84 | + v1 |
| 85 | + config-version: |
| 86 | + #string.used by customer to keep track of this config file's version in their source control/repository (max allowed 10 chars, other chars will be truncated) |
| 87 | + ver1 |
| 88 | + prometheus-collector-settings: |- |
| 89 | + cluster_alias = "" |
| 90 | + default-scrape-settings-enabled: |- |
| 91 | + kubelet = true |
| 92 | + coredns = false |
| 93 | + cadvisor = true |
| 94 | + kubeproxy = false |
| 95 | + apiserver = false |
| 96 | + kubestate = true |
| 97 | + nodeexporter = true |
| 98 | + windowsexporter = false |
| 99 | + windowskubeproxy = false |
| 100 | + kappiebasic = true |
| 101 | + prometheuscollectorhealth = false |
| 102 | + # Regex for which namespaces to scrape through pod annotation based scraping. |
| 103 | + # This is none by default. Use '.*' to scrape all namespaces of annotated pods. |
| 104 | + pod-annotation-based-scraping: |- |
| 105 | + podannotationnamespaceregex = ".*" |
| 106 | + default-targets-metrics-keep-list: |- |
| 107 | + kubelet = "" |
| 108 | + coredns = "" |
| 109 | + cadvisor = "" |
| 110 | + kubeproxy = "" |
| 111 | + apiserver = "" |
| 112 | + kubestate = "" |
| 113 | + nodeexporter = "" |
| 114 | + windowsexporter = "" |
| 115 | + windowskubeproxy = "" |
| 116 | + podannotations = "" |
| 117 | + kappiebasic = "" |
| 118 | + minimalingestionprofile = true |
| 119 | + default-targets-scrape-interval-settings: |- |
| 120 | + kubelet = "30s" |
| 121 | + coredns = "30s" |
| 122 | + cadvisor = "30s" |
| 123 | + kubeproxy = "30s" |
| 124 | + apiserver = "30s" |
| 125 | + kubestate = "30s" |
| 126 | + nodeexporter = "30s" |
| 127 | + windowsexporter = "30s" |
| 128 | + windowskubeproxy = "30s" |
| 129 | + kappiebasic = "30s" |
| 130 | + prometheuscollectorhealth = "30s" |
| 131 | + podannotations = "30s" |
| 132 | + debug-mode: |- |
| 133 | + enabled = false |
| 134 | +EOF |
| 135 | +``` |
| 136 | + |
| 137 | +In a few minutes, the `ama-metrics` pods in the `kube-system` namespace should restart and pick up the new configuration. |
| 138 | + |
| 139 | +## Review visualization of metrics in Azure Managed Grafana |
| 140 | + |
| 141 | +Now that you have Azure Monitor managed service for Prometheus and Azure Managed Grafana configured, you should [access your Managed Grafana instance][access-grafana]. |
| 142 | + |
| 143 | +There are two [official ingress-nginx dashboards](https://github.com/kubernetes/ingress-nginx/tree/main/deploy/grafana/dashboards) dashboards that you can download and import into your Grafana instance: |
| 144 | + |
| 145 | +- Ingress-nginx controller dashboard |
| 146 | +- Request handling performance dashboard |
| 147 | + |
| 148 | +### Ingress-nginx controller dashboard |
| 149 | + |
| 150 | +This dashboard gives you visibility of request volume, connections, success rates, config reloads and configs out of sync. You can also use it to view the network IO pressure, memory and CPU use of the ingress controller. Finally, it also shows the P50, P95, and P99 percentile response times of your ingresses and their throughput. |
| 151 | + |
| 152 | +You can download this dashboard from [GitHub][grafana-nginx-dashboard]. |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +### Request handling performance dashboard |
| 157 | + |
| 158 | +This dashboard gives you visibility into the request handling performance of the different ingress upstream destinations, which are your applications' endpoints that the ingress controller is forwarding traffic to. It shows the P50, P95 and P99 percentile of total request and upstream response times. You can also view aggregates of request errors and latency. Use this dashboard to review and improve the performance and scalability of your applications. |
| 159 | + |
| 160 | +You can download this dashboard from [GitHub][grafana-nginx-request-performance-dashboard]. |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | +### Importing a dashboard |
| 165 | + |
| 166 | +To import a Grafana dashboard, expand the left menu and click on **Import** under Dashboards. |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +Then upload the desired dashboard file and click on **Load**. |
| 171 | + |
| 172 | + |
| 173 | +## Next steps |
| 174 | + |
| 175 | +- You can configure scaling your workloads using ingress metrics scraped with Prometheus using [Kubernetes Event Driven Autoscaler (KEDA)][KEDA]. Learn more about [integrating KEDA with AKS][keda-prometheus]. |
| 176 | +- Create and run a load test with [Azure Load Testing][azure-load-testing] to test workload performance and optimize the scalability of your applications. |
| 177 | + |
| 178 | +<!-- LINKS - internal --> |
| 179 | +[az-aks-create]: /cli/azure/aks#az-aks-create |
| 180 | +[app-routing]: /azure/aks/app-routing |
| 181 | +[managed-prometheus]: /azure/azure-monitor/essentials/prometheus-metrics-overview |
| 182 | +[managed-prometheus-configure]: /azure/azure-monitor/essentials/prometheus-metrics-enable?tabs=cli |
| 183 | +[managed-prometheus-custom-annotations]: /azure/azure-monitor/essentials/prometheus-metrics-scrape-configuration#pod-annotation-based-scraping |
| 184 | +[managed-grafana]: /azure/managed-grafana/overview |
| 185 | +[create-grafana]: /azure/managed-grafana/quickstart-managed-grafana-portal |
| 186 | +[access-grafana]: /azure/managed-grafana/quickstart-managed-grafana-portal#access-your-managed-grafana-instance |
| 187 | +[keda]: /azure/aks/keda-about |
| 188 | +[keda-prometheus]: /azure/azure-monitor/essentials/integrate-keda#scalers |
| 189 | +[azure-load-testing]: /azure/load-testing/quickstart-create-and-run-load-test |
| 190 | +[az-aks-show]: /cli/azure/aks#az-aks-show |
| 191 | +[az-aks-enable-addons]: /cli/azure/aks#az-aks-enable-addons |
| 192 | +[az-aks-disable-addons]: /cli/azure/aks#az-aks-disable-addons |
| 193 | +[az-aks-install-cli]: /cli/azure/aks#az-aks-install-cli |
| 194 | +[az-aks-get-credentials]: /cli/azure/aks#az-aks-get-credentials |
| 195 | +[az-extension-add]: /cli/azure/extension#az-extension-add |
| 196 | +[az-extension-update]: /cli/azure/extension#az-extension-update |
| 197 | +[install-azure-cli]: /cli/azure/install-azure-cli |
| 198 | +[az-keyvault-create]: /cli/azure/keyvault#az_keyvault_create |
| 199 | +[az-keyvault-certificate-import]: /cli/azure/keyvault/certificate#az_keyvault_certificate_import |
| 200 | +[az-keyvault-certificate-show]: /cli/azure/keyvault/certificate#az_keyvault_certificate_show |
| 201 | +[az-network-dns-zone-create]: /cli/azure/network/dns/zone#az_network_dns_zone_create |
| 202 | +[az-network-dns-zone-show]: /cli/azure/network/dns/zone#az_network_dns_zone_show |
| 203 | +[az-role-assignment-create]: /cli/azure/role/assignment#az_role_assignment_create |
| 204 | +[az-aks-addon-update]: /cli/azure/aks/addon#az_aks_addon_update |
| 205 | +[az-keyvault-set-policy]: /cli/azure/keyvault#az_keyvault_set_policy |
| 206 | + |
| 207 | +<!-- LINKS - external --> |
| 208 | +[osm-release]: https://github.com/openservicemesh/osm/releases/ |
| 209 | +[nginx]: https://kubernetes.github.io/ingress-nginx/ |
| 210 | +[external-dns]: https://github.com/kubernetes-incubator/external-dns |
| 211 | +[kubectl]: https://kubernetes.io/docs/reference/kubectl/ |
| 212 | +[kubectl-apply]: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply |
| 213 | +[grafana-nginx-dashboard]: https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/grafana/dashboards/request-handling-performance.json |
| 214 | +[grafana-nginx-request-performance-dashboard]: https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/grafana/dashboards/request-handling-performance.json |
0 commit comments