日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用Prometheus发现在Kubernetes上运行的应用程序

發布時間:2023/12/3 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Prometheus发现在Kubernetes上运行的应用程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Prometheus支持抓取應用程序的多個實例。 由于其IP地址會發生變化,因此需要動態發現在協調環境中運行的應用程序。 可以將Prometheus配置為使用Kubernetes API動態地發現正在運行的實例列表中的更改。

下面顯示了一個簡單的Prometheus示例,該示例對具有多個Pod實例的應用程序進行檢測。

普羅米修斯配置

我們配置Prometheus來發現我們的config-example應用程序的pod。

global: scrape_interval: 15s external_labels: monitor: 'example-monitor' scrape_configs: - job_name: 'example-metric' scrape_interval: 5s metrics_path: /metrics/ scheme: https basic_auth: username: admin password: adminadmin tls_config: insecure_skip_verify: true kubernetes_sd_configs: - role: endpoints namespaces: names: - default relabel_configs: - source_labels: [__meta_kubernetes_service_label_app] separator: ; regex: config-example replacement: $ 1 action: keep - source_labels: [__meta_kubernetes_endpoint_port_name] separator: ; regex: https replacement: $ 1 action: keep - source_labels: [__meta_kubernetes_namespace] separator: ; regex: (.*) target_label: namespace replacement: $ 1 action: replace - source_labels: [__meta_kubernetes_pod_name] separator: ; regex: (.*) target_label: pod replacement: $ 1 action: replace - source_labels: [__meta_kubernetes_service_name] separator: ; regex: (.*) target_label: service replacement: $ 1 action: replace - source_labels: [__meta_kubernetes_service_name] separator: ; regex: (.*) target_label: job replacement: ${ 1 } action: replace - separator: ; regex: (.*) target_label: endpoint replacement: https action: replace

我們需要調整app標簽(在此處為config-example )和端口名稱( https ),在該端口下可以使用監視端點。

儀表應用

本示例使用在Open Liberty之上運行的MicroProfile Metrics端點。 該應用程序在端口9443和路徑/metrics/下以Prometheus格式公開/metrics/ 。

在這里,您可以看到示例服務和部署:

kind: Service apiVersion: v1 metadata: name: config-example labels: app: config-example spec: selector: app: config-example ports: - port: 9443 name: https - port: 9080 name: http kind: Deployment apiVersion: apps/v1beta1 metadata: name: config-example spec: replicas: 2 template: metadata: labels: app: config-example spec: containers: - name: config-example image: sdaschner/config-example: 1 # ...

您可以在GitHub上找到完整的示例,包括正在運行的應用程序。

Prometheus設置和RBAC

為了使該示例適用于RBAC Kubernetes設置,Prometheus服務帳戶需要具有正確的權限。 因此,我們將在此處創建服務帳戶和相應的群集角色,如YAML定義中所述。 同樣,我們在創建Prometheus部署時指定服務帳戶。

我們為Prometheus實例創建部署和服務。

kind: Service apiVersion: v1 metadata: name: prometheus labels: app: prometheus spec: selector: app: prometheus ports: - port: 9090 name: http kind: Deployment apiVersion: apps/v1beta1 metadata: name: prometheus spec: replicas: 1 template: metadata: labels: app: prometheus version: v1 spec: serviceAccountName: prometheus containers: - name: prometheus image: prom/prometheus:v2. 7.1 ports: 9090 - containerPort: 9090 volumeMounts: - name: prometheus-config-volume mountPath: /etc/prometheus/prometheus.yml subPath: prometheus.yml volumes: - name: prometheus-config-volume configMap: name: prometheus-config restartPolicy: Always

前面顯示的配置可以從配置映射中注入實例。

kind: ConfigMap apiVersion: v1 metadata: name: prometheus-config data: prometheus.yml: | global: scrape_interval: 15s # content as shown earlier ...

有關Prometheus配置的完整說明,請參閱文檔 。

訪問目標

現在,正在運行的Prometheus實例可以發現兩個正在運行的配置示例應用程序,它們都作為Kubernetes容器運行:

gt; kubectl get pods NAME READY STATUS RESTARTS AGE config-example-69974cbc96-dqd96 gt; kubectl get pods NAME READY STATUS RESTARTS AGE config-example-69974cbc96-dqd96 1 / 1 Running 0 4m config-example-69974cbc96-zstg7 1 / 1 Running 0 4m grafana-8694db9d4f-nvn5s 1 / 1 Running 0 3m prometheus-594dd9cdb8-95ftz 1 / 1 Running 0 3m

我們可以在Prometheus配置下看到實際目標,包括其IP地址。

看一下GitHub上的完整示例。 您可能還會看到以下視頻,了解如何使用MicroProfile在Java EE應用程序中實現業務指標。

對于定義了更多應用程序的更復雜的微服務示例,使用純Prometheus配置的這種方法可能有點麻煩。 為了減少樣板代碼,開發人員可以使用抽象化較低層配置的解決方案,例如Prometheus Operator 。 在下一篇文章中,我們將看到Prometheus Operator如何促進應用程序的配置。

監控愉快!

翻譯自: https://www.javacodegeeks.com/2019/02/applications-running-kubernetes-prometheus.html

總結

以上是生活随笔為你收集整理的使用Prometheus发现在Kubernetes上运行的应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。