From point A to point B
Point A: you have applications spread across dozens of pods that scale on their own. When something is slow, where do you look? Point B: by the end of this chapter you'll know which data tells you what's happening and why, how to set reliability targets, and how to set up monitoring with Prometheus and Grafana, both on Docker and on Kubernetes.
This chapter completes the Cloud Native Architecture domain (12% of the KCNA exam). It's a long chapter because observability is the competency with the most hands-on content in the domain.
- Logs, metrics and traces
- SLI, SLO, SLA and the error budget
- Prometheus: architecture, exporters and metrics
- Monitoring containers and Kubernetes
- Cost management in the cloud
What observability is
Observability is the ability to understand and measure a system's state from the data it generates itself. It's not just about knowing what failed, but why.
The difference from classic monitoring matters. Monitoring means watching for what you already know can fail: a full disk, a server that's down. Observability is for the unexpected: in a dynamic, distributed environment, with microservices that come and go, it lets you ask the data new questions and get answers that help you act. It also makes it easier for teams to work together, because everyone looks at the same data.
Logs, metrics and traces
Observability relies on three kinds of data, known as its three pillars:
Each pillar answers a different question. Diagram: The House of Routing.
- Logs: text messages with a timestamp. They tell you what happened, in detail. In Kubernetes, containers write to standard output, and an agent such as Fluent Bit or Fluentd, deployed as a DaemonSet, collects them and sends them to a central store.
- Metrics: numeric values measured over time, such as CPU usage, memory, errors or latency. They're cheap to store and perfect for alerts and trends.
- Traces: they follow a request hop by hop through every service it passes through, with the time spent in each one. They're the tool for finding where time is lost in a microservices architecture. Jaeger is the best-known CNCF project for storing and viewing them.
2026-10-27T06:41:12Z INFO checkout order=8812 user=4410 total=59.90
2026-10-27T06:41:13Z ERROR payment order=8812 provider=timeout after=3000ms
SLI, SLO and SLA
Measuring for the sake of it doesn't help. You have to decide which measurement matters to the user and which value is acceptable. That's what three concepts from SRE practice are for:
- SLI (Service Level Indicator): a measurement of the service you provide, such as latency, availability or error rate. Not every metric works as an SLI: the best ones reflect the user's experience, which is why error rate is usually more useful than plain uptime.
- SLO (Service Level Objective): the target value or range for an SLI. For example, "latency below 100 ms". It quantifies the reliability the product promises the customer.
- SLA (Service Level Agreement): the contract between the provider and the customer that guarantees a level of service, with consequences, such as credits or penalties, if it isn't met.
The SLI measures, the SLO sets the goal and the SLA sets the consequences. Diagram: The House of Routing.
The SLO gives you the error budget: if the target is 99.9%, you can afford to fail the remaining 0.1%. While there's budget left, the team can take risks with new deployments; once it runs out, stability comes first.
SLI share of HTTP requests answered without error in under 300 ms
SLO 99.9% over 30 days
error budget = 0.1% → about 43 minutes of failures per month
SLA below 99.5% in a month, the customer gets a 10% credit
Prometheus
Prometheus is an open source monitoring system, graduated in the CNCF, that collects metrics from many sources, stores them, and lets you query them, visualize them and create alerts. It's designed for one specific kind of data: numeric time series, such as CPU or memory usage, disk space, availability, latency or pending requests.
Its architecture has three main parts:
- Collection (retrieval): requests the metrics from the targets.
- Time series database (TSDB): stores them.
- HTTP server: answers queries in PromQL, its query language, on port 9090.
Prometheus requests metrics from its targets, stores them and notifies Alertmanager. Diagram: The House of Routing.
Prometheus follows a pull model: it visits each target at regular intervals and reads its /metrics endpoint, instead of waiting for the data to be sent to it. Each of those reads is called a scrape. That way, if a target stops responding, Prometheus notices right away. For short jobs that finish before the next scrape, there's the Pushgateway, where they leave their metrics for Prometheus to collect.
Around the server there are two more pieces: Alertmanager, which groups alerts and sends them by email, Slack or PagerDuty, and Grafana, which isn't part of Prometheus but is the usual way to build dashboards with its data.
Exporters and configuration
What if the application or system doesn't offer a /metrics endpoint? There are two solutions:
- Exporters: programs that collect a system's metrics and expose them in Prometheus format. The best known is node exporter, which publishes a Linux machine's metrics: CPU, memory, disk and network. There are also exporters for databases, web servers and almost anything else.
- Client libraries: for Go, Python, Java, Ruby, Rust and other languages. You use them in your own code to expose business metrics: number of errors, runs, request latency or job duration.
# download node_exporter from prometheus.io/download, then:
tar xvf node_exporter-*.linux-amd64.tar.gz
cd node_exporter-*.linux-amd64 && ./node_exporter &
curl http://localhost:9100/metrics | head # it listens on port 9100
Installing the exporter isn't enough: Prometheus is very static, and you have to tell it where to fetch metrics from. You do that in its configuration file, prometheus.yml, with one job per group of targets. The default prometheus job makes Prometheus monitor itself.
# /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s # how often Prometheus pulls the targets
scrape_configs:
- job_name: prometheus # the default job: Prometheus watches itself
static_configs:
- targets: ["localhost:9090"]
- job_name: nodes
static_configs:
- targets: ["192.168.1.11:9100", "192.168.1.12:9100"]
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
# or, if started with --web.enable-lifecycle:
curl -X POST http://localhost:9090/-/reload
Prometheus metrics
Every metric has a name, some labels (key-value pairs) and a value. The HELP and TYPE lines describe the metric and say what type it is:
# HELP http_requests_total Total HTTP requests handled.
# TYPE http_requests_total counter
http_requests_total{method="GET",code="200",path="/api"} 10427
http_requests_total{method="GET",code="500",path="/api"} 13
Each combination of name and labels forms a separate time series, and each sample is stored with a Unix timestamp: the seconds elapsed since January 1, 1970, UTC. Labels let you filter and group, for example by method or by response code. But use them wisely: a label with unlimited values, such as a user ID, creates millions of series and can bring Prometheus down. Internally, even the metric name is a special label, __name__.
| Type | What it measures | Examples |
|---|---|---|
| Counter | How many times something happened. It only goes up (or resets to zero on restart) | Total requests, exceptions, jobs run |
| Gauge | The current value, which can go up and down | CPU in use, free memory, concurrent requests |
| Histogram | How long something takes or how big it is, grouped into ranges (buckets) | Response time, request size |
| Summary | Similar to a histogram, but calculates percentiles on the client itself | 95th percentile latency |
With PromQL you turn those series into answers:
node_memory_MemAvailable_bytes # gauge: memory available now
rate(http_requests_total[5m]) # counter → requests per second
sum by (code) (rate(http_requests_total[5m])) # grouped by status code
histogram_quantile(0.95,
sum by (le) (rate(http_request_duration_seconds_bucket[5m]))) # 95th percentile latency
Monitoring containers
With Docker there are two sources of metrics, and they complement each other:
- Docker engine metrics: the state of the daemon itself. You enable them with the
metrics-addroption indaemon.json. - cAdvisor: an agent that runs as a container and measures each container's usage, such as CPU, memory, network and disk.
# 1. Docker engine metrics: /etc/docker/daemon.json
{ "metrics-addr": "127.0.0.1:9323" }
sudo systemctl restart docker
# 2. Per-container metrics with cAdvisor
docker run -d --name cadvisor -p 8080:8080 \
-v /:/rootfs:ro -v /var/run:/var/run:ro -v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
gcr.io/cadvisor/cadvisor:v0.49.1
Then, in Prometheus, you add one job for each source:
scrape_configs:
- job_name: docker
static_configs:
- targets: ["192.168.1.20:9323"]
- job_name: cadvisor
static_configs:
- targets: ["192.168.1.20:8080"]
Monitoring Kubernetes
You can monitor a cluster from an external Prometheus, but the recommended approach is to install it inside the cluster. In Kubernetes there are three levels to monitor: the applications, the containers and the cluster itself with its components. Covering them takes several pieces:
- node exporter as a DaemonSet: instead of installing it by hand on every node, a DaemonSet puts a pod with the exporter on each node, including nodes added later.
- kube-state-metrics: Prometheus doesn't know the state of Kubernetes objects on its own. This component translates it into metrics: desired and available replicas, pod restarts, Deployments that aren't progressing…
- kubelet and cAdvisor: the kubelet on each node already includes cAdvisor and exposes each container's usage.
- Service discovery: Prometheus queries the Kubernetes API to find only the pods, Services and nodes it should monitor, with no fixed IP lists.
kube-prometheus-stack installs Prometheus, Alertmanager, Grafana and the exporters in the cluster. Diagram: The House of Routing.
Installing it all by hand is complex and error-prone. The recommended way is to use Helm, the Kubernetes package manager. A Helm chart is a collection of templates and YAML files that become Kubernetes manifests: each application is packaged as its own chart. The kube-prometheus-stack chart installs everything at once:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install monitoring prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace
kubectl get pods -n monitoring # prometheus, alertmanager, grafana,
# kube-state-metrics, node-exporter…
kubectl port-forward -n monitoring svc/monitoring-grafana 3000:80
This chart relies on the Prometheus Operator, which adds its own resources to Kubernetes. With a ServiceMonitor you tell Prometheus which Services to monitor, in YAML and without touching prometheus.yml:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: web
namespace: monitoring
labels:
release: monitoring # so the Prometheus of the chart picks it up
spec:
namespaceSelector:
matchNames: ["apps"]
selector:
matchLabels:
app: web # Services with this label…
endpoints:
- port: metrics # …are scraped on their "metrics" port
interval: 30s
Cost management
Observability also helps you control spending. Cloud cost management means linking resource usage to what it costs and keeping it under control. It's the foundation of the FinOps practice. It has three fronts:
1. Choose the right type of infrastructure:
| Instance type | How you pay | When it makes sense |
|---|---|---|
| On-demand | Per use, with no commitment | Variable or unpredictable workloads |
| Reserved | A one- to three-year commitment, with a large discount | Stable workloads that are always on |
| Spot | Spare capacity, very cheap, that the provider can reclaim with little notice | Interruption-tolerant jobs, such as batch or CI |
2. Balance performance and cost: size each resource correctly (rightsizing), set suitable upper and lower limits for autoscaling, and choose the right performance metrics to trigger it.
3. Eliminate waste: shut down non-essential environments outside business hours and on weekends, and review the infrastructure continuously to delete what's no longer used: orphaned disks, forgotten load balancers, abandoned test environments.
KCNA-style challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. Which pillar of observability follows a request across several services?
Traces. Logs record events and metrics measure values over time.
2. "Latency must be below 100 ms 99% of the time." Is this an SLI, an SLO or an SLA?
An SLO: it's a target for an SLI, latency. It would be an SLA if it were a contract with consequences for the provider.
3. How does Prometheus get metrics from its targets?
With a pull model: it visits each target's /metrics endpoint at regular intervals.
4. Which metric type would you use for a node's free memory?
A gauge, because the value goes up and down. A counter can only go up.
5. Prometheus can't see how many replicas a Deployment has available. What's missing?
kube-state-metrics, which turns the state of Kubernetes objects into metrics.
Key takeaways
- Observability explains the why from the system's own data: logs, metrics and traces.
- OpenTelemetry standardizes how all three are generated and sent; Jaeger stores traces and Fluent Bit collects logs.
- The SLI is what you measure, the SLO is the goal and the SLA is the contract; the error budget is the margin the SLO leaves.
- Prometheus stores only numeric metrics, follows a pull model over /metrics and is queried with PromQL.
- Exporters and client libraries expose metrics; prometheus.yml says which targets to scrape.
- Metric types: counter, gauge, histogram and summary.
- On Kubernetes: node exporter as a DaemonSet, kube-state-metrics, and kube-prometheus-stack with Helm.
- Cost management: on-demand, reserved and spot instances, rightsizing, and removing unused resources.
With this chapter you close the Cloud Native Architecture domain. The next one brings the last domain: application delivery, with CI/CD and GitOps.
Official resources
- Prometheus: Overviewprometheus.io
- Prometheus: Metric typesprometheus.io
- Prometheus: Configurationprometheus.io
- Querying Prometheus (PromQL)prometheus.io
- Node Exporterprometheus.io
- kube-prometheus-stackgithub.com
- kube-state-metricsgithub.com
- OpenTelemetryopentelemetry.io
- Jaegerjaegertracing.io
- Google SRE Book: Service Level Objectivessre.google
- Kubernetes and Cloud Native Associate (KCNA)cncf.io
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's KCNA course (January to April 2026). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details and configuration examples were checked against the official Prometheus, Kubernetes, OpenTelemetry and CNCF documentation.