【问题标题】:My Pod is not appering in the prometheus targets我的 Pod 没有出现在 prometheus 目标中
【发布时间】:2021-04-12 06:45:24
【问题描述】:
我的 Pod 没有出现在 prometheus 目标中
应用程序正在公开指标“/metrics”
我添加了一个服务监视器来公开服务
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: abc
# Change this to the namespace the Prometheus instance is running in
# namespace: default
labels:
app: abc
release: prometheus
spec:
selector:
matchLabels:
app: abc # target gitlab service
endpoints:
- port: http
interval: 15s
path: /metrics
但 prometheus 仍然无法读取指标
【问题讨论】:
标签:
kubernetes
prometheus
【解决方案1】:
确保您的 pod 有一个名为“app”的标签
Labels: app=<appname>
如果您使用 helpm 图表,请在 {{chart-name}}\templates_helpers.tpl 中的帮助程序中添加标签
{{/*
Selector labels
*/}}
{{- define "<appname>.selectorLabels" -}}
app.kubernetes.io/name: {{ include "<appname>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ .Release.Name }} # <======================================= add this
{{- end }}
将“”替换为您的应用名称
检查您的 pod 是否出现在 http://localhost:9090/config 中
rule_files:
- /etc/prometheus/rules/prometheus-prometheus-kube-prometheus-prometheus-rulefiles-0/*.yaml
scrape_configs:
- job_name: default/<appname>y/0
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
relabel_configs:
- source_labels: [__meta_kubernetes_service_label_app]
separator: ;
regex:
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: http
replacement: $1
action: keep