背景
我已经使用普罗米修斯舵图在我的Kubernetes集群(由托管)上安装了Prometheus。
问题
我不知道如何将刮伤目标添加到Prometheus服务器。prometheus.io站点描述了如何将prometheus.yml文件(其中包含刮取目标的列表)挂载到prometheus.yml容器--我已经在本地完成了这一工作。但是,我不知道如何为通过Kubernetes-Helm安装的Prometheus设置指定刮擦目标。是否需要向包含刮取目标的Prometheus服务器荚添加卷,从而更新由Helm生成的YAML文件?
我也不清楚如何在Kubernetes Pod中公开度量标准--我需要转发特定的端口吗?
发布于 2021-11-22 23:20:02
首先,您需要创建一个服务监视器,这是一个定制的K8s资源。只需在清单文件夹中创建一个servicemonitor.yaml即可。
因为当我们在K8s上部署时,我们没有访问Prometheus.yaml文件的权限来提到目标,所以我们创建了servicemonitor,它反过来将目标添加到Prometheus.yaml文件中的scrap_config中。你可以从这里上读到更多关于它的信息。
这是一个示例servicemonitor.yaml文件,用于在Prometheus中公开Flask度量标准。
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还可以在元数据和规范部分中将此发布标签添加到服务和部署文件中。
如果遇到普罗米修斯显示目标而不是端点的情况,请查看以下内容:https://github.com/prometheus-operator/prometheus-operator/issues/3053
一些有用的链接:
https://stackoverflow.com/questions/45613660
复制相似问题