在 helm chart kube-prometheus-stack 部署中添加自定义抓取端点

Add custom scrape endpoints in helm chart kube-prometheus-stack deployment

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

所以我正在努力获得这个的 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 deployment(然后是node port service)添加了如下注解:

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

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

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

在您的 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: :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 完成上述指标和 re-install Prometheus 之后,现在我可以看到目标,并且指标得到公开。