![](/img/trans.png)
[英]How do i pass a standalone mysql container as a dependency to a service in kubernetes-helm?
[英]How do you add scrape targets to a Prometheus server that was installed with Kubernetes-Helm?
背景
我已经使用Prometheus的Helm 图表在我的 Kubernetes 集群(托管在 Google Container Engineer 上) 上安装了 Prometheus 。
问题
我不知道如何将抓取目标添加到 Prometheus 服务器。 prometheus.io 站点描述了我如何将 prometheus.yml 文件(其中包含抓取目标列表)挂载到 Prometheus Docker 容器——我已经在本地完成了这个并且它有效。 但是,我不知道如何为通过 Kubernetes-Helm 安装的 Prometheus 设置指定抓取目标。 我是否需要向包含抓取目标的 Prometheus 服务器 pod 添加一个卷,从而更新 Helm 生成的 YAML 文件?
我也不清楚如何在 Kubernetes Pod 中公开指标——我是否需要转发特定端口?
您需要为要监视的服务添加注释。
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: 'true'
来自图表中的prometheus.yml:
prometheus.io/scrape
:只抓取值为true
prometheus.io/scheme
或https prometheus.io/path
:如果指标路径不是/metrics
则覆盖 prometheus.io/port
:如果度量标准在不同的端口上公开 是的,您需要向服务公开端口,以便Prometheus可以访问它
首先需要创建一个Service Monitor,它是一个自定义的K8s资源。 只需在清单文件夹中创建一个servicemonitor.yaml
。
由于在 K8s 上部署时,我们无法访问 Prometheus.yaml 文件来提及目标,因此我们创建了 servicemonitor,它将目标添加到 Prometheus.yaml 文件中的 scrap_config 中。 您可以从这里阅读更多相关信息。
这是一个示例servicemonitor.yaml
文件,用于在 Prometheus 中公开 Flask App 指标。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: flask-metrics
namespace: prometheus # namespace where prometheus is running
labels:
app: flask-app
release: prom # name of the release
# ( VERY IMPORTANT: You need to know the correct release name by viewing
# the servicemonitor of Prometheus itself: Without the correct name,
# Prometheus cannot identify the metrics of the Flask app as the target.)
spec:
selector:
matchLabels:
# Target app service
app: flask-app # same as above
release: prom # same as above
endpoints:
- interval: 15s # scrape interval
path: /metrics # path to scrape
port: http # named port in target app
namespaceSelector:
matchNames:
- flask # namespace where the app is running
还要将此版本标签添加到服务和部署文件的元数据和规范部分。
如果您遇到 Prometheus 显示目标而不显示端点的情况,请查看: https : //github.com/prometheus-operator/prometheus-operator/issues/3053
一些有用的链接:
我已经在这个答案中结束了我 12 小时的研究。 如果您觉得有用,请为答案点赞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.