Monitor Kubernetes with Prometheus and Grafana: Guide

Knowing how to monitor Kubernetes with Prometheus and Grafana is the difference between catching a pod crash loop at 2 AM yourself and hearing about it from angry users at 9 AM. The pair works well together: Prometheus scrapes metrics from your cluster and stores them as time series, and Grafana turns those time series into dashboards and alerting you can actually act on. This guide walks through the full setup on any reasonably recent Kubernetes cluster: installing with Helm, checking that metrics flow, importing the standard dashboards, and writing alerts that matter.

Before starting, make sure you have kubectl pointed at a working cluster, Helm 3 installed, and enough spare resources for the monitoring stack itself (the full bundle asks for roughly 2 CPU and 4 GB RAM across its pods). If you are still getting comfortable with the basics, this practical guide to Kubernetes covers clusters, pods, and deployments without assuming prior experience.

Installing the stack to monitor Kubernetes with Prometheus and Grafana

The fastest reliable way to get both running is the community chart that ships the tools plus exporters and a default alert set in one release. Add the repo and install it into its own namespace:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack 
  --namespace monitoring --create-namespace 
  --set prometheus.prometheusSpec.retention=30d

Retention defaults to 10 days, which is fine for a homelab but too short for trend analysis on a production cluster. Setting 30 days at install time costs storage but saves you from a gap in history right when you need it. If you are unsure how much disk that means, budget roughly 1-2 GB per 100k active time series per day; a small cluster usually lands well under 50 GB.

Wait for the pods, then confirm the stack sees your cluster:

kubectl get pods -n monitoring
kubectl -n monitoring port-forward svc/kube-prometheus-stack-prometheus 9090:9090

Open localhost:9090 and run up in the query box. From here you can query Prometheus Kubernetes metrics directly with PromQL. Every entry should read 1. If something reads 0, the target list under Status > Targets tells you exactly which endpoint is failing, which is usually the fastest debugging hint you will get all week.

Opening Grafana and importing the key dashboards

Grafana ships in the same release, pre-configured to talk to Prometheus as its default data source:

kubectl -n monitoring port-forward svc/kube-prometheus-stack-grafana 3000:80

Sign in at localhost:3000 with user admin. Grab the generated password first:

kubectl -n monitoring get secret kube-prometheus-stack-grafana 
  -o jsonpath="{.data.admin-password}" | base64 --decode

The chart already installs the two Grafana Kubernetes dashboards you will open daily: one for node resource usage (CPU, memory, disk, network per node) and one for pod compute resources (CPU and memory per workload). Do not skip past them to build something custom yet. These cover the majority of real incidents: a node filling its disk, a pod slowly eating memory, one deployment suddenly pinned at 100% CPU.

If you are comparing monitoring platforms before committing, this comparison of Prometheus vs Zabbix vs Checkmk breaks down the tradeoffs honestly. And if Grafana itself is new to you, the Datadog vs New Relic vs Grafana observability guide explains where Grafana fits in a larger observability stack.

Scraping your own application metrics

Out of the box, Prometheus scrapes cluster-level metrics through kube-state-metrics and the node exporter. For your own services, the modern pattern is a ServiceMonitor custom resource that tells the Prometheus operator what to scrape. The minimal version for a service exposing metrics on /metrics:

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

The critical detail is the release: kube-prometheus-stack label. Without it, the operator ignores your ServiceMonitor and your metrics never appear. It is the single most common reason people ask why their app metrics are missing, and it takes two seconds to fix once you know.

Writing alerts that actually page you

Dashboards are for investigation; alerts are for response. Your Kubernetes alerting rules live in PrometheusRule resources. Start with a small set tied to user impact rather than trying to alert on every metric you can think of.

Three rules worth having on day one:

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: app-alerts
  namespace: monitoring
  labels:
    release: kube-prometheus-stack
spec:
  groups:
    - name: app-health
      interval: 30s
      rules:
        - alert: PodCrashLooping
          expr: |
            rate(kube_pod_container_status_restarts_total[15m]) > 0
          for: 5m
          labels:
            severity: critical
          annotations:
            summary: "Pod {{ $labels.pod }} is crash looping"
        - alert: PodMemoryRisingFast
          expr: |
            rate(container_memory_working_set_bytes{container!=""}[15m]) > 0
            and on(pod) (container_memory_working_set_bytes{container!=""}
            / container_spec_memory_limit_bytes) > 0.9
          for: 10m
          labels:
            severity: warning
          annotations:
            summary: "Pod {{ $labels.pod }} above 90% memory limit"
        - alert: NodeDiskFillingUp
          expr: |
            node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} /
            node_filesystem_size_bytes < 0.15
          for: 10m
          labels:
            severity: warning
          annotations:
            summary: "Disk on {{ $labels.instance }} below 15% free"

Apply it with kubectl apply -f app-alerts.yaml and check under Status > Rules in the Prometheus UI that each rule resolves without an error. Alerts land in Alertmanager; wire a receiver for email, Slack, or PagerDuty in the chart values under alertmanager.config before you call the setup done. An alert nobody receives is decoration.

Tuning retention, cardinality, and cost

Two settings decide whether your monitoring bill and storage stay sane. First, keep retention aligned with your actual troubleshooting window. A 30-day retention is fine for weekly reviews; if nobody ever looks back more than 7 days, drop it and reclaim the disk.

Second, watch metric cardinality. Every label combination creates a new time series, and sloppy labels are how a small cluster ends up with millions of series. Run this in the Prometheus query box to find the worst offenders:

topk(10, count by (__name__)({__name__=~".+"}))

If one metric dominates, check whether it carries high-cardinality labels like user IDs or request paths. You cannot fix that at the label level, but you can drop the metric entirely with metricRelabelings on the scrape config if it is not pulling its weight.

For workload sizing, a good pairing is to plan your autoscaling thresholds against the same metrics you alert on. This guide to setting up the Kubernetes HPA shows how to drive scaling from CPU, memory, and custom Prometheus metrics, so your alerts and your autoscaling read from the same source of truth.

Keeping the setup maintainable

Three habits keep this stack healthy over months. First, pin your chart version in a values file and upgrade deliberately; the operator and CRDs change, and blind helm upgrade runs across major versions can rename resources under you. Second, treat your dashboards and rules as code: export them from Grafana and commit them to the same repo as your manifests. Third, periodically open the Prometheus targets page and delete scrape configs for namespaces that no longer exist. Stale targets are quiet until they are not.

Done right, this setup takes about an hour and gives you cluster visibility, application metrics, dashboards, and alerting from a single Helm release. Start with the defaults, add alerts for the things that wake you up, and tune retention once you know what you actually look at.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.