Monitoring

Prometheus 自動從 kubernetes 中的多個 kube-state-metrics 中抓取指標?

  • October 27, 2020

我想使用具有多個 kube-state-metrics 的 kubernetes(cluster-0) 來監控多個其他 kubernetes 集群(cluster-1,2,3,4)

在 (cluster-0) 中,我拆分為多個命名空間,如下所示:

namespace: monitor

(here I will run prometheus to scrape metrics from other kube-state-metrics pod)
namespaces: cluster-0
(here I will run kube-state-metrics pod to monitor cluster-0
....
namespaces: cluster-4
(here I will run kube-state-metrics pod to monitor cluster-4)
...

等等…

這裡的問題是我將如何設置 prometheus 來自動抓取新的 kube-state-metrics,因為我將非常快速地擴展 kubernetes 集群,或者縮小它。以及如何區分它們之間的不同指標,比如有一個標題……

我嘗試使用配置,但- targets: ['serviceIP:8080']在我的情況下僅定位單個並不是很好。

正如我在評論中已經提到的那樣。你需要的是Kubernetes 上的 Prometheus Self Discovery

Kubernetes Self Discovery 配置允許在新目標出現時自動檢索抓取目標。抓取是基於 Kubernetes 服務名稱的,因此即使 IP 地址發生變化(並且它們會發生變化),Prometheus 也可以無縫地抓取目標。

Prometheus 自我發現基於此處解釋的 Kubernetes 標籤和註釋。這允許在選擇要抓取的應用程序時有很大的粒度。在這裡了解角色欄位也很重要,因為它定義了抓取作業的行為。角色定義了您希望 Prometheus 查找的 Kubernetes 資源的類型。目前它可以是端點、服務、pod、節點或入口。例如,如果角色設置為 pod,Prometheus 將為每個 pod 發現一個目標,並將其容器公開為目標。

有了它,您將能夠在新節點出現時從新節點中刪除指標。可以在連結的文件中找到更多詳細資訊和範例。

引用自:https://serverfault.com/questions/1038933