TL;DR
Learn how to implement comprehensive monitoring and observability in Kubernetes clusters using Prometheus, Grafana, and other tools for effective cluster management.
Executive Summary
A Kubernetes cluster without observability is a system you operate by anecdote. This guide sets out a working stack — Prometheus for metrics, Loki for logs, OpenTelemetry for traces, Grafana for visualisation, Alertmanager for paging — and, more importantly, the decisions behind it: which signals matter, which metrics to alert on, and which to leave on dashboards. By the end you will be able to decide what to collect, how long to keep it, and how to alert on symptoms your users feel rather than causes they do not.
Why This Matters
Kubernetes fails in ways that are invisible from outside the cluster: a pod crash-looping on one node, a node quietly saturating its disk, a deployment whose new version doubles its error rate for 2% of requests. Without metrics you find out from users; without logs you cannot say why; without traces you cannot say where. The cost is measured in incident duration — every minute of "we don't know" during an outage is a minute added directly to your MTTR, and observability is the only investment that reliably shortens it.
Core Concepts
The Three Signals, and What Each One Answers
Metrics answer "is something wrong, and how big is it" — cheap, aggregatable, alertable. Logs answer "what exactly happened here" — expensive, detailed, indispensable during diagnosis. Traces answer "where did this request spend its time" across service boundaries. A complete setup collects all three and links them: an alert fires from a metric, the dashboard shows the affected service, the trace shows the slow hop, the logs show the error. Skipping any one of the three leaves a class of incidents undiagnosable.
Prometheus: Metrics Collection and Service Discovery
Prometheus is the de facto standard for Kubernetes metrics because it discovers its targets from the Kubernetes API itself — pods, nodes, and services appear as scrape targets automatically as they are created:
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'kubernetes-nodes'
kubernetes_sd_configs:
- role: node
relabel_configs:
- source_labels: [__meta_kubernetes_node_name]
target_label: nodeTwo companion components do most of the real work. node-exporter runs on every node and exposes host-level metrics (CPU, memory, disk, network). kube-state-metrics exposes the state of Kubernetes objects themselves — pod phases, deployment replica mismatches, restart counts. Application pods expose their own /metrics endpoints. The most useful starting metrics are:
| Metric type | What it tells you | Importance |
|---|---|---|
| Node CPU/memory | Resource utilisation and saturation risk | High |
| Pod status | Application health, crash loops, pending pods | Critical |
| Network I/O | Communication patterns and anomalies | Medium |
| Disk usage | Storage capacity, inode exhaustion | High |
The discipline that matters most is cardinality: every unique label value combination is a separate time series. Labels like user IDs or request IDs in metrics will explode memory and cost. High-cardinality data belongs in logs and traces, never in metric labels.
Visualisation with Grafana
Grafana turns Prometheus data into the dashboards an on-call engineer actually reads at 3 AM. Dashboards can be provisioned as code, alongside the applications they describe:
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboard
data:
kubernetes-cluster.json: |
{
"dashboard": {
"title": "Kubernetes Cluster Overview",
"panels": [
{
"title": "CPU Usage",
"type": "graph",
"datasource": "Prometheus",
"targets": [
{
"expr": "sum(rate(container_cpu_usage_seconds_total{container!=\"\"}[5m])) by (pod)"
}
]
}
]
}
}Build dashboards around the questions incidents ask — "which pods are consuming the node", "what changed in the last hour", "which service's latency moved" — not around every metric you happen to collect.
Log Aggregation with Loki
Centralised logging is essential because pod logs die with the pod. Promtail runs on each node, tails pod logs, attaches Kubernetes metadata as labels, and ships them to Loki:
apiVersion: v1
kind: ConfigMap
metadata:
name: promtail-config
data:
promtail.yaml: |
server:
http_listen_port: 9080
positions:
filename: /run/promtail/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
scrape_configs:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: podLoki indexes only labels, not full log text, which makes it far cheaper to run than full-text indexing systems — at the cost of slower ad-hoc searches across large volumes. Two practices matter more than the tool: structured (JSON) logs with consistent field names, and retention policies set deliberately per environment rather than by default.
Alerting on Symptoms, Not Causes
Alertmanager receives alerts from Prometheus, groups them, deduplicates them, and routes them to the right channel with escalation. Rules are declared as code:
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: kubernetes-alerts
spec:
groups:
- name: kubernetes
rules:
- alert: HighCPUUsage
expr: sum(rate(container_cpu_usage_seconds_total{container!=""}[5m])) by (pod) > 0.8
for: 5m
labels:
severity: warning
annotations:
description: "Pod {{ $labels.pod }} has high CPU usage"The for: duration is doing quiet, critical work: it prevents a thirty-second spike from paging a human. The deeper rule is to alert on user-facing symptoms (error rate, latency, saturation against an SLO) rather than on causes (one pod's CPU) — cause-based alerts fire constantly for conditions the system absorbs on its own, and alert fatigue is how real pages get ignored. Every alert should have a documented response; an alert nobody acts on should be deleted.
Distributed Tracing with OpenTelemetry
Traces follow a single request across services, which is the only reliable way to localise latency in a microservices system. OpenTelemetry is the vendor-neutral standard for instrumentation; a collector receives spans and exports them to a backend such as Jaeger:
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: cluster-collector
spec:
config: |
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
processors:
batch:
exporters:
jaeger:
endpoint: jaeger-collector:14250
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [jaeger]Sample deliberately: capturing every trace is rarely necessary, and tail-based sampling — keeping traces that contain errors or unusual latency — preserves the useful ones at a fraction of the storage cost.
Decision Framework
| Situation | Recommendation |
|---|---|
| Starting from zero on a self-managed cluster | Prometheus + node-exporter + kube-state-metrics + Grafana; add Loki next |
| Small team, no appetite for operating the stack | A managed observability platform (Grafana Cloud, Datadog, New Relic) |
| Log volume is huge and searches are rare | Loki — label indexing keeps storage cost low |
| Log searches are forensic and frequent | A full-text indexing system (Elasticsearch/OpenSearch) instead |
| Microservices latency is the main pain | OpenTelemetry tracing before more metrics |
| Regulated environment | Self-host the stack inside your boundary; audit log retention is a compliance input |
Implementation Checklist
Trade-offs
This stack is powerful and it is also a production system in its own right: Prometheus needs storage planning as series counts grow, Loki and trace backends consume real resources, and every component needs its own monitoring. Cardinality discipline is a permanent tax on developers. Managed platforms remove most of that operational weight at a per-host or per-series price that grows with exactly the success you are hoping for. There is no free option — there is a choice between paying in engineering time or in invoice line items.
When Not to Use
Conclusion
Observability in Kubernetes is a discipline before it is a toolset: metrics to detect, logs to explain, traces to localise, and alerts reserved for symptoms a human must act on. Build the stack in that order, keep cardinality and retention under deliberate control, and test the paging path before an incident does it for you.
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.