KubernetesIntermediate

Kubernetes Monitoring and Observability: A Complete Guide

8 min read

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.

The stack in one picture Three signals, one pane of glass, one paging path. Prometheus metrics · alerts Loki logs · labels only OpenTelemetry traces · spans Grafana one pane of glass for all three Metrics detect, logs explain, traces localise — Grafana is where they meet.

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.

One incident, three signals Follow the chain in order — each signal answers the next question. Alert metric crosses SLO Dashboard which service? Trace which hop is slow? Log what was the error? Skip one signal and a whole class of incidents becomes 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: node

Two 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 typeWhat it tells youImportance
Node CPU/memoryResource utilisation and saturation riskHigh
Pod statusApplication health, crash loops, pending podsCritical
Network I/OCommunication patterns and anomaliesMedium
Disk usageStorage capacity, inode exhaustionHigh

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: pod

Loki 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

Which shape fits your team? The right stack follows the team, not the tool catalogue. Starting from zero? team size · appetite · pain Self-managed Prometheus stack Small team managed platform Latency is the pain tracing first There is no free option — only a choice between paying in engineering time or invoice lines.

SituationRecommendation
Starting from zero on a self-managed clusterPrometheus + node-exporter + kube-state-metrics + Grafana; add Loki next
Small team, no appetite for operating the stackA managed observability platform (Grafana Cloud, Datadog, New Relic)
Log volume is huge and searches are rareLoki — label indexing keeps storage cost low
Log searches are forensic and frequentA full-text indexing system (Elasticsearch/OpenSearch) instead
Microservices latency is the main painOpenTelemetry tracing before more metrics
Regulated environmentSelf-host the stack inside your boundary; audit log retention is a compliance input

Implementation Checklist

  • [ ] Prometheus scraping nodes, kube-state-metrics, and application pods — verified in the targets UI
  • [ ] No high-cardinality labels (user IDs, request IDs) in any metric
  • [ ] Dashboards provisioned as code and versioned with the applications
  • [ ] Pod logs reaching Loki (or your aggregator) with namespace/pod labels attached
  • [ ] Structured logging adopted by the main services, with a documented field convention
  • [ ] Every paging alert tied to a user-visible symptom and a written response procedure
  • [ ] Alert grouping and deduplication configured in Alertmanager; escalation path tested
  • [ ] Trace sampling strategy chosen and collector deployed
  • [ ] Retention set explicitly for metrics, logs, and traces — not left at tool defaults
  • [ ] A game-day or test alert has paged the on-call end to end at least once
  • 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

  • A single small application on a managed platform: if you run three pods on GKE/EKS with no platform team, the cloud provider's built-in monitoring plus structured logs is enough; do not build an observability platform to watch one service.
  • Prometheus for long-term analytics: it is an operational monitoring system, not a data warehouse. For months-long trend analysis, remote-write to a long-term store (Thanos, Mimir, or a managed equivalent) instead.
  • Tracing before basic metrics and logs: if you cannot yet answer "is it up and how fast", traces will not save you. Sequence the signals in order of diagnostic value per unit of effort.
  • 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.

    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.