实现目标:
在新集群中部署prometheus代理服务,收集到 servicemonitor数据后,写到外部prometheus 实例
同时,禁止安装 node_exporter、altermanager、grafana
- 安装helm源
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
- values.xml
#完整参考: https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml
prometheus:
agentMode: true
prometheusSpec:
remoteWrite:
- url: "http://you-prometheus-host:9090/api/v1/write"
podMonitorNamespaceSelector: {}
podMonitorSelector: {}
podMonitorSelectorNilUsesHelmValues: false
ruleNamespaceSelector:
ruleSelector: {}
ruleSelectorNilUsesHelmValues: false
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
serviceMonitorSelectorNilUsesHelmValues: false
alertmanager:
enabled: false
grafana:
enabled: false
nodeExporter:
enabled: false
- 部署脚本
# 安装
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace -f values.yml
# 更新
helm upgrade kube-prometheus-stack prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace -f values.yml
# 删除
# helm delete kube-prometheus-stack
至此,就可以监听所有namespace 下的 ServiceMonitors 、PodMonitors 对象了。