单机 Prometheus 存在数据丢失、查询瓶颈和容量上限。需要多副本采集、长期存储、跨集群统一查询,或要求 Prometheus 重启后历史数据仍可查。
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install monitoring prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace \
--set prometheus.replicas=2 \
--set alertmanager.replicas=3
--set prometheus.prometheusSpec.externalLabels.cluster=prod
--set prometheus.prometheusSpec.replicaExternalLabelName=prometheus_replica
--set prometheus.prometheusSpec.thanos.objectStorageConfig.secretName=thanos-objstore
--set prometheus.prometheusSpec.thanos.objectStorageConfig.key=objstore.yml
cat > objstore.yml <<'EOF'
type: S3
config:
bucket: thanos
endpoint: minio.storage:9000
access_key: minio
secret_key: minio123
insecure: true
EOF
kubectl -n monitoring create secret generic thanos-objstore --from-file=objstore.yml
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install thanos bitnami/thanos \
--namespace monitoring \
--set query.replicaCount=2 \
--set storegateway.enabled=true \
--set compactor.enabled=true \
--set objstoreConfig="$(cat objstore.yml)"
让 Grafana 数据源指向 Thanos Query,而不是单个 Prometheus。查询时按 cluster 和 prometheus_replica 去重。
Alertmanager 组成集群,配置相同的 --cluster.peer 和静默规则,避免重复告警。
replicaExternalLabelName,查询结果重复或互相覆盖。promtool — 检查规则和配置amtool — 管理 Alertmanager 告警与静默thanos — 查询、存储网关和压缩kubectl — 查看 Prometheus/Thanos 状态mc — 检查对象存储中的块