DevopsIntermediate

Monitoring Kubernetes Clusters with Prometheus and Grafana

DeveloperHat Team
9 min read

TL;DR

A comprehensive guide to implementing effective monitoring for your Kubernetes clusters using Prometheus and Grafana.

Monitoring Kubernetes Clusters with Prometheus and Grafana

Executive Summary

Prometheus and Grafana are the standard open-source monitoring stack for Kubernetes: Prometheus scrapes metrics from the cluster and your workloads, Alertmanager routes the alerts, and Grafana turns the data into dashboards. This guide covers the architecture (node exporter, kube-state-metrics, the metrics pipeline), installation with Helm, the signals actually worth watching — cluster resources, workload health, and the golden signals of your services — plus alert design, recording rules, and the retention and cardinality problems that bite at scale. After reading it, you will be able to stand up a cluster monitoring baseline and know which dashboards and alerts earn their place.

Why This Matters

Kubernetes fails in ways that are invisible from outside the cluster. A pod can be running and useless — crash-looping on one replica, starved of CPU by a missing request, or silently dropped from a Service by a label mismatch — while the node's average utilisation looks calm. Without metrics you learn about these states from users. The cost is not just detection time; it is diagnosis time, because an incident bridge guessing at causes burns the same clock as an incident bridge reading a dashboard that already shows which layer broke. Monitoring is also the evidence base for capacity and reliability decisions: whether the cluster needs nodes, whether a service's limits are sane, and whether an error budget is being spent on change or on decay. A cluster you cannot observe is a cluster you are operating on faith.

Core Concepts

The Metrics Pipeline

Three sources cover most of what you need. Node exporter runs on every node and exposes host-level metrics: CPU, memory, disk, and network. kube-state-metrics watches the Kubernetes API and exposes the state of objects — how many pods are pending, how many restarts a deployment has accumulated, what resources workloads requested versus what exists. Application metrics come from your services themselves, exposed on an HTTP endpoint in Prometheus format and discovered through ServiceMonitor resources when running the Prometheus Operator. Prometheus scrapes all of these on an interval, stores them as time series, and evaluates alerting and recording rules against them. Grafana reads from Prometheus; it stores nothing itself.

Installation with Helm

The community charts are the standard install path. Install Prometheus (which brings node exporter and kube-state-metrics) and Grafana into a dedicated monitoring namespace:

# Add Prometheus Helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

# Install Prometheus
helm install prometheus prometheus-community/prometheus \
  --namespace monitoring \
  --create-namespace

# Add Grafana Helm repository
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

# Install Grafana
helm install grafana grafana/grafana \
  --namespace monitoring \
  --set persistence.enabled=true \
  --set persistence.size=10Gi

Size persistence for your retention target and set retention explicitly; defaults tuned for a demo will quietly discard the history you need during the first serious incident review:

# prometheus-values.yaml
server:
  persistentVolume:
    size: 50Gi
  retention: 15d

alertmanager:
  enabled: true
  
  persistence:
    enabled: true
    size: 10Gi

nodeExporter:
  enabled: true

kubeStateMetrics:
  enabled: true

Many teams instead install the kube-prometheus-stack chart, which bundles the Prometheus Operator, curated dashboards, and a sensible default alert rule set. Either way, treat the monitoring stack as production infrastructure: version it, configure it as code, and monitor it.

What to Watch: Cluster, Workloads, Services

Organise dashboards by the question being asked. For resources, the USE method (utilisation, saturation, errors) applied per node and per workload catches capacity problems: CPU throttling against limits, memory working set approaching limits, pods pending for lack of allocatable resources. For workload health, watch replica availability, restart counts, and rollout state from kube-state-metrics. For services, the four golden signals from Google's SRE practice — latency, traffic, errors, saturation — usually in the RED form (rate, errors, duration) per service. Application endpoints are wired in with a ServiceMonitor:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: app-monitor
spec:
  selector:
    matchLabels:
      app: myapp
  endpoints:
  - port: metrics

A Grafana panel is then a PromQL query over the scraped series:

{
  "dashboard": {
    "id": null,
    "title": "Kubernetes Cluster Overview",
    "panels": [
      {
        "title": "CPU Usage",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(container_cpu_usage_seconds_total{container!=\"\"}[5m])) by (pod)"
          }
        ]
      }
    ]
  }
}

Prefer the community-maintained cluster and namespace dashboards over hand-rolled ones; they encode years of operational experience about which aggregations are meaningful.

Alerting Without the Noise

Alerts should fire on symptoms users can feel, or on saturation that reliably predicts symptoms — not on every anomaly a metric can express. Each alert needs a threshold, a duration (for) so transient spikes do not page, a severity, and an annotation that tells the responder what is wrong:

# Node alerts
groups:
- name: node.rules
  rules:
  - alert: NodeHighCPU
    expr: instance:node_cpu_utilisation:rate5m > 0.8
    for: 10m
    labels:
      severity: warning
    annotations:
      description: "CPU usage on {{ $labels.instance }} is above 80%"

# Pod alerts
groups:
- name: pod.rules
  rules:
  - alert: PodHighMemory
    expr: container_memory_usage_bytes > 1.5 * 1024 * 1024 * 1024
    for: 5m
    labels:
      severity: warning
    annotations:
      description: "Pod {{ $labels.pod }} is using too much memory"

Route through Alertmanager with grouping and silences so one cluster event produces one notification, and review alert quality regularly: an alert that fires and is ignored is worse than no alert, because it trains the team to ignore the channel. Page on a short list (service down, error budget burning fast, cluster capacity exhausted); ticket or chat-notify the rest.

Recording Rules, Retention, and Cardinality

Recording rules precompute expensive queries into new time series, which keeps dashboards fast and consistent:

groups:
- name: custom.rules
  rules:
  - record: job:http_requests_total:rate5m
    expr: rate(http_requests_total[5m])

Query discipline matters for the same reason — aggregate before you present, and avoid per-pod series in cluster-wide panels:

# Bad query
rate(http_requests_total[5m])

# Better query
sum by (service) (rate(http_requests_total[5m]))

The structural limit to plan around is cardinality: every unique label combination is a new time series, so labels must never carry unbounded values such as user IDs, request IDs, or full URLs. High cardinality is the most common cause of Prometheus memory blow-ups, ahead of retention length. For retention beyond a few weeks or across many clusters, the standard answers are remote write to a long-term store (Thanos, Cortex, Mimir, or a managed Prometheus service) while keeping local Prometheus for fast recent queries and alerting.

Decision Framework

SituationRecommendation
First cluster, small teamkube-prometheus-stack with default dashboards and alerts; customise only what pages you
Several clustersOne Prometheus per cluster for alerting, remote write to central long-term storage for queries
Strict cost constraintsShorter local retention, aggressive recording rules, audit label cardinality before adding exporters
Regulated environmentCentralised, access-controlled Grafana; retained metrics and alert history as audit evidence
Applications with custom business metricsExpose a metrics endpoint per service and add ServiceMonitors; keep label values bounded
Existing enterprise monitoring platform mandatedExport or remote-write into it rather than running a shadow stack, if it can ingest Prometheus data

Implementation Checklist

  • [ ] Node exporter and kube-state-metrics are scraping on every cluster, with scrape health itself alerted
  • [ ] Prometheus has persistent storage and an explicit retention setting matched to incident-review needs
  • [ ] Every production service exposes metrics and has a ServiceMonitor or scrape configuration
  • [ ] Dashboards exist for cluster capacity, workload health, and per-service golden signals
  • [ ] Alerts have thresholds, durations, severities, and annotations a responder can act on
  • [ ] Alertmanager routes, groups, and can silence notifications; the paging list is short and symptom-based
  • [ ] No label carries unbounded values; cardinality is reviewed when new exporters or metrics are added
  • [ ] Recording rules back the expensive dashboard queries
  • [ ] The monitoring stack's own availability is checked from outside the cluster it monitors
  • Trade-offs

    Prometheus is a pull-based, single-node-at-heart design: superb for scraping and alerting within a cluster, but high availability and long-term storage are architectures you build around it rather than features it ships. Its operational cost is real — someone owns upgrades, storage growth, and rule quality. Grafana dashboards proliferate without governance until nobody knows which panel is authoritative. And metrics are only one leg of observability: they tell you that latency rose, not why; logs and traces answer the follow-up questions, and a metrics-only stack will leave incident bridges correlating timestamps by hand.

    When Not to Use

    Do not build a self-hosted Prometheus and Grafana stack for a very small, short-lived cluster if your cloud provider's managed monitoring already covers nodes and workloads adequately — the operating cost of the stack can exceed the cluster's. Do not use Prometheus as a long-term analytics or billing data store; its retention and query model are built for operational time windows, and business reporting belongs in a warehouse. And do not start with custom application metrics everywhere — instrument the golden signals for critical services first, because a hundred bespoke metrics nobody graphs are worse than ten standard ones everybody trusts.

    Conclusion

    Stand up Prometheus with node exporter and kube-state-metrics, give it real storage and retention, and build dashboards around capacity, workload health, and golden signals. Keep alerts few, symptom-based, and actionable, and watch cardinality before it watches you. That baseline turns cluster incidents from archaeology into reading — which is the entire point of the stack.

    References

    Here are valuable resources for Kubernetes monitoring:

  • Prometheus Documentation - Official Prometheus documentation
  • Grafana Documentation - Official Grafana documentation
  • Kubernetes Monitoring Guide - Official K8s monitoring guide
  • Prometheus Operator - Automated Prometheus setup
  • Grafana Dashboards - Pre-built Grafana dashboards
  • Kubernetes Metrics - K8s metrics reference
  • PromQL Basics - Prometheus Query Language guide
  • Alertmanager - Prometheus alerting
  • Kubernetes Best Practices - K8s monitoring best practices
  • Service Monitoring - Application monitoring guide
  • These resources provide comprehensive information about monitoring Kubernetes clusters effectively.

    Why This Matters

    Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.

    Trade-offs to Consider

    Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.

    When NOT to Use This

    Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.

    Decision Framework

    Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.

    Share this articleShare on XShare on LinkedIn

    Keep the decision frameworks coming

    One practical architecture guide a week — patterns, trade-offs, and when not to use them. No spam, unsubscribe anytime.