在Kubernetes上使用Prometheus Operator监视应用程序
您可以使Prometheus配置了解您的應(yīng)用程序在其中運行的Kubernetes環(huán)境。在先前的博客文章中 ,我已經(jīng)描述了如何手動執(zhí)行該操作。 Prometheus Operator是Kubernetes的擴展,它以更自動化和有效的方式管理Prometheus監(jiān)視實例。
Prometheus Operator允許您將監(jiān)視實例定義和管理為Kubernetes資源。 如果您知道如何管理Kubernetes,則入門門檻很低,可以有效地定義對應(yīng)用程序的監(jiān)視。
為了為Prometheus運營商啟用Kubernetes,我們設(shè)置了資源和RBAC定義,您可以在此處找到它們。 這通過更多的Kubernetes資源類型(例如ServiceMonitor或Prometheus增強了我們的集群。 同樣,您可以使用Prometheus Operator 舵圖 。
我們定義了config-example應(yīng)用程序的運算符,類似于上一篇文章:
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: config-example labels: team: example spec: selector: matchLabels: app: config-example endpoints: - basicAuth: password: name: basic-auth key: password username: name: basic-auth key: username port: https scheme: https path: '/metrics/' tlsConfig: insecureSkipVerify: true apiVersion: monitoring.coreos.com/v1 kind: Prometheus metadata: name: prometheus spec: serviceAccountName: prometheus serviceMonitorSelector: matchLabels: team: example resources: requests: memory: 400Mi apiVersion: v1 kind: Service metadata: name: prometheus spec: ports: - port: 9090 name: http selector: prometheus: prometheus apiVersion: v1 kind: Secret metadata: name: basic-auth data: password: YWRtaW5hZG1pbg== username: YWRtaW4=這將設(shè)置一個prometheus實例,該實例將使用提供的配置來訪問通過app: config-example標(biāo)簽部署的app: config-example 。 它還創(chuàng)建了一個prometheus服務(wù)來訪問監(jiān)視實例。
您可以在文檔中找到Prometheus Operator API的完整說明。
應(yīng)用所有資源后,我們可以看到集群中正在運行的監(jiān)視實例:
gt; kubectl get pods NAME READY STATUS RESTARTS AGE config-example-7db586bb95-jdmsx gt; kubectl get pods NAME READY STATUS RESTARTS AGE config-example-7db586bb95-jdmsx 1 / 1 Running 0 12m config-example-7db586bb95-z4ln8 1 / 1 Running 0 12m [...] prometheus-prometheus- 0 3 / 3 Running 0 14m這使我們能夠簡單地監(jiān)視所有應(yīng)用程序?qū)嵗?#xff0c;而無需手動配置Prometheus實例。
查看GitHub上的完整示例( deployment/目錄)。
發(fā)現(xiàn)帖子有用嗎? 訂閱我的時事通訊,獲取有關(guān)IT和Java的更多免費內(nèi)容,技巧和竅門:
成功! 現(xiàn)在檢查您的電子郵件以確認(rèn)您的訂閱。
?Sebastian Daschner,CC BY-NC-SA 4.0
翻譯自: https://www.javacodegeeks.com/2019/02/monitor-prometheus-kubernetes.html
總結(jié)
以上是生活随笔為你收集整理的在Kubernetes上使用Prometheus Operator监视应用程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ddos是什么意思啊(我一直ddos啥意
- 下一篇: 在注协备案的审计报告(在注协备案)