在Kubernetes上使用Prometheus Operator监视应用程序
您可以使Prometheus配置了解您的應用程序在其中運行的Kubernetes環境。在先前的博客文章中 ,我已經描述了如何手動執行該操作。 Prometheus Operator是Kubernetes的擴展,它以更自動化和有效的方式管理Prometheus監視實例。
Prometheus Operator允許您將監視實例定義和管理為Kubernetes資源。 如果您知道如何管理Kubernetes,則入門門檻很低,可以有效地定義對應用程序的監視。
為了為Prometheus運營商啟用Kubernetes,我們設置了資源和RBAC定義,您可以在此處找到它們。 這通過更多的Kubernetes資源類型(例如ServiceMonitor或Prometheus增強了我們的集群。 同樣,您可以使用Prometheus Operator 舵圖 。
我們定義了config-example應用程序的運算符,類似于上一篇文章:
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=這將設置一個prometheus實例,該實例將使用提供的配置來訪問通過app: config-example標簽部署的app: config-example 。 它還創建了一個prometheus服務來訪問監視實例。
您可以在文檔中找到Prometheus Operator API的完整說明。
應用所有資源后,我們可以看到集群中正在運行的監視實例:
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這使我們能夠簡單地監視所有應用程序實例,而無需手動配置Prometheus實例。
查看GitHub上的完整示例( deployment/目錄)。
發現帖子有用嗎? 訂閱我的時事通訊,獲取有關IT和Java的更多免費內容,技巧和竅門:
成功! 現在檢查您的電子郵件以確認您的訂閱。
?Sebastian Daschner,CC BY-NC-SA 4.0
翻譯自: https://www.javacodegeeks.com/2019/02/monitor-prometheus-kubernetes.html
總結
以上是生活随笔為你收集整理的在Kubernetes上使用Prometheus Operator监视应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ddos是什么意思啊(我一直ddos啥意
- 下一篇: 将旧对象装箱可自动关闭