Skills2026年4月16日·1 分钟阅读

Prometheus Operator — Kubernetes-Native Monitoring Stack Management

Prometheus Operator simplifies deploying and managing Prometheus, Alertmanager, and related monitoring components on Kubernetes using custom resources and reconciliation loops.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Prometheus Operator Overview
直接安装命令
npx -y tokrepo@latest install 064a2633-3943-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Prometheus Operator manages Prometheus and Alertmanager on Kubernetes via custom resources.
§01

What it is

Prometheus Operator is a Kubernetes operator that automates the deployment and management of Prometheus, Alertmanager, and related monitoring components. Instead of writing raw Kubernetes manifests for monitoring infrastructure, you define custom resources like Prometheus, ServiceMonitor, and AlertmanagerConfig. The operator watches these resources and reconciles the actual state to match your declarations.

Prometheus Operator targets SREs, DevOps engineers, and platform teams who run Kubernetes and need a production-grade monitoring stack that scales with their cluster without manual configuration management.

§02

How it saves time or tokens

Without the operator, deploying Prometheus on Kubernetes requires managing StatefulSets, ConfigMaps with scrape configs, RBAC rules, and persistent volumes manually. The operator handles all of this through custom resources. Adding a new scrape target is as simple as creating a ServiceMonitor resource; the operator automatically updates the Prometheus configuration.

For teams managing multiple clusters, the operator provides a consistent, declarative approach to monitoring that can be versioned and replicated through GitOps workflows.

§03

How to use

  1. Install the Prometheus Operator using Helm: helm install prometheus prometheus-community/kube-prometheus-stack. This deploys Prometheus, Alertmanager, Grafana, and the operator.
  2. Create a ServiceMonitor custom resource to scrape metrics from your application. The operator detects the resource and configures Prometheus automatically.
  3. Define alerting rules with PrometheusRule resources. The operator loads them into Prometheus without manual config reloads.
§04

Example

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: my-app-monitor
  labels:
    release: prometheus
spec:
  selector:
    matchLabels:
      app: my-app
  endpoints:
    - port: metrics
      interval: 30s
      path: /metrics

This ServiceMonitor tells Prometheus to scrape the /metrics endpoint of any service labeled app: my-app every 30 seconds. No manual Prometheus config editing required.

§05

Related on TokRepo

§06

Common pitfalls

  • ServiceMonitor labels must match the Prometheus resource's serviceMonitorSelector. If your monitors are not being picked up, check the label matching between Prometheus and ServiceMonitor resources.
  • The kube-prometheus-stack Helm chart deploys many components by default (Grafana, node-exporter, kube-state-metrics). Disable components you do not need to reduce resource usage.
  • Prometheus stores metrics locally by default. For long-term retention, configure a remote write destination like Thanos, Cortex, or Mimir.

常见问题

What is the difference between Prometheus and Prometheus Operator?+

Prometheus is the monitoring system that scrapes and stores metrics. Prometheus Operator is a Kubernetes operator that automates deploying and configuring Prometheus using custom resources. The operator manages the lifecycle of Prometheus instances on Kubernetes.

Does the operator support high availability?+

Yes. You can configure multiple Prometheus replicas through the Prometheus custom resource. The operator handles replica management, and tools like Thanos can deduplicate data across replicas for HA queries.

Can I use Prometheus Operator without Helm?+

Yes. You can deploy the operator using raw Kubernetes manifests or kustomize. The Helm chart (kube-prometheus-stack) is the most common installation method because it bundles everything, but it is not required.

How do I add alerting rules?+

Create a PrometheusRule custom resource with your alerting rules in the standard Prometheus alerting format. The operator detects the resource and loads the rules into Prometheus. No restart or config reload is needed.

Does Prometheus Operator work with managed Kubernetes?+

Yes. It works on EKS, GKE, AKS, and any conformant Kubernetes cluster. The operator uses standard Kubernetes APIs and does not depend on cloud-provider-specific features.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产