# AKS with Prometheus ###### tags: `Technical` `AKS` `Prometheus` ## 架構 ![](https://i.imgur.com/vGMT9gl.png) - Exporter:必須把想要傳送給 Prometheus 的資料給暴露出來,例如安裝於 Node 上 - Prometheus:組態中會決定要去哪些 Exporter 把資料給拉 (Pull) 回來 - Alertmanager:根據定義的 Notification 組態決定要通知的方法 ## 建立 Prometheus on Docker https://prometheus.io/docs/prometheus/latest/installation/ ``` docker run -p 9090:9090 -v path/to/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus ``` http://localhost:9090 ![](https://i.imgur.com/BlsgnC2.png) ## 安裝 Exporter only on AKS https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-node-exporter - Cluster IP ``` helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace monitoring --create-namespace ``` - External Load Balancer ``` helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace monitoring --create-namespace --set service.type=LoadBalancer ``` - 後續也可以用helm upgrade來進行變更 ``` helm upgrade prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace monitoring --create-namespace --set service.type=LoadBalancer ``` ## 確認 Pod 正常運行 ``` kubectl get pods --namespace monitoring ``` ![](https://i.imgur.com/kTSNoL8.png) ## 確認 Exporter IP and Port ``` kubectl get svc --namespace monitoring ``` ![](https://i.imgur.com/rpho3tX.png) ## 可透過 Port-Forward 測試 Metrics ``` kubectl port-forward -n=monitoring svc/prometheus-node-exporter 9100:9100 ``` http://localhost:9100/metrics ![](https://i.imgur.com/Nu5l9tf.png) ## 在 Prometheus Server 新增此 Exporter 資訊 - 將targets位置輸入svc的IP地址 - 如果使用docker執行,使用port-forward測試下,要連線到localhost的話需要使用host.docker.internal:9100這個路徑 ```yaml scrape_configs: - job_name: AKS metrics_path: /metrics static_configs: - targets: - [EXPORTER_SVC_IP]:9100 ``` ## 確認 Target 狀態,並可以正常得到 Node 參數 ![](https://i.imgur.com/YtJEZFZ.png) ![](https://i.imgur.com/67BXkTL.png)