【问题标题】:Add custom scrape endpoints in helm chart kube-prometheus-stack deployment在 helm chart kube-prometheus-stack 部署中添加自定义抓取端点
【发布时间】:2020-10-20 20:36:28
【问题描述】:

首先对使用 helm 有点陌生...

所以我很难得到这个的掌舵部署:https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

在我的 kubernetes 集群中按照我想要的方式工作。我喜欢它到目前为止所做的事情,但我怎样才能让它刮掉一个自定义端点?我看过这个:https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus

在标题为:“通过注释抓取 Pod 指标”的部分下。我在 kubernetes 的 pod 部署(然后是节点端口服务)中添加了以下注释:

annotations = {
 "prometheus.io/scrape" = "true"
 "prometheus.io/path"   = "/appMetrics/prometheusMetrics"
 "prometheus.io/port"   = "443"
}

但是,当我查看 prometheus 的 targets 页面时,我看不到它。我也没有在配置文件中看到它。所以这让我觉得这个 helm 图表没有部署相同的 prometheus 图表。

所以现在的问题是,如何使用 helm chart kube-prometheus-stack 设置自定义抓取端点。从我的阅读来看,这是我应该*使用的,对吧?

【问题讨论】:

标签: kubernetes prometheus kubernetes-helm


【解决方案1】:

在您的 custom_values.yaml 中试试这个并应用它。

prometheus:
  prometheusSpec:
    additionalScrapeConfigs:
      - job_name: your_job_name
        scrape_interval: 15s
        kubernetes_sd_configs:
        - role: pod
          namespaces:
            names:
              - your_namespace
        relabel_configs:
        - source_labels: [__meta_kubernetes_namespace]
          action: replace
          target_label: namespace
        - source_labels: [__meta_kubernetes_pod_name]
          action: replace
          target_label: pod
        - source_labels: [__address__]
          action: replace
          regex: ([^:]+)(?::\d+)?
          replacement: ${1}:your_port
          target_label: __address__
        - source_labels: [__meta_kubernetes_pod_label_app]
          action: keep
          regex: your_pod_name

您需要将your_job_nameyour_namespaceyour_portyour_pod_name 替换为您的部署文件。在我完成上述指标并通过 helm chart 重新安装 Prometheus 之后,现在我可以看到目标,并且指标暴露出来了。

【讨论】:

  • 文档链接或此 yaml 来源的参考将非常有帮助。对于我们这些不熟悉这项技术的人来说,任何关于这些值应该包含什么的解释(如job_name)都会很好。
  • 我也是这方面的新手,而且是很久以前的事了。我不记得我搜索了什么。但是你可以用谷歌搜索它,关于这部分有很多提示/文档。例如在google中搜索“prometheus adapter prometheusSpec additionalScrapeConfigs”然后开始阅读。
猜你喜欢
  • 2022-08-11
  • 2021-09-06
  • 1970-01-01
  • 2021-06-26
  • 2021-04-30
  • 2021-06-27
  • 2022-08-05
  • 1970-01-01
  • 2021-05-12
相关资源
最近更新 更多