prometheus operator 自定义 config

链接:prometheus-operator/Documentation/additional-scrape-config.md at · GitHub

prometheus 实例增加如下配置:

# kubectl edit prometheus example-prometheus -n monitoring

spec:
additionalScrapeConfigs:
name: additional-scrape-configs
key: prometheus-additional.yaml

prometheus-additional.yaml 配置如下:

- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# 生成 secrete config yaml
kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run=client -oyaml > additional-scrape-configs.yaml

# 执行命令生成 secrete
kubectl apply -f additional-scrape-configs.yaml -n monitoring

# 查看生成的 secrete 内容
kubectl -n monitoring get secrets additional-scrape-configs -o jsonpath='{.data.prometheus-additional\.yaml}' | base64 -d


prometheus operator 配置 remote_write

kubectl -n monitoring edit prometheus k8s
# 修改成如下配置
spec:
remoteWrite:
- url: http://vminsert:8480/insert/0/prometheus/

# 查看config
# secrete 文件内容经过 gzip 压缩,要查看的话需要解压
kubectl -n monitoring get secrets prometheus-k8s -o jsonpath='{.data.prometheus\.yaml\.gz}' | base64 -d | gzip -d

prometheus operator 配置 external_labels

# 编辑 prometheus 实例
kubectl edit prometheus k8s -n monitoring

# 增加如下配置
spec:
externalLabels:
cluster: "test-1"
environment: "production"

参考