Kubernetes generates hundreds of metrics per pod, per node, per control plane component. Without a strategy, you collect everything, store everything, and understand nothing. This guide teaches you to identify the key signals that reveal real problems (OOMKilled, pending pods, excessive restarts, nodes not ready), to tell apart the 3 metrics sources (kube-state-metrics, cAdvisor, kubelet), and to avoid the pitfalls that blow up your cardinality and your costs. By the end, you will know how to set up effective Kubernetes monitoring that detects real problems without drowning your Prometheus (in French), the software that collects and stores metrics.
What you will learn
- The 4 layers of K8s observability: application, container, node, control plane, and why you must cover each one
- The 3 metrics sources: kube-state-metrics, cAdvisor, kubelet, their role, what they expose, how to scrape them properly
- The 5 key signals: OOMKilled, pod restarts, pending pods, node not ready, CPU throttling, the exact metrics and the PromQL queries
- Kubernetes logs: pod stdout/stderr, control plane logs, volume pitfalls
- The cardinality trap: why K8s labels blow up Prometheus and how to protect yourself
- Noisy neighbors: detecting and isolating workloads that over-consume shared resources
- Essential alerts: 8 production-ready alerts for a minimal K8s cluster
- Anti-patterns: the classic mistakes that make your monitoring useless or ruinous
Prerequisites
This guide assumes you can read a Kubernetes manifest (Deployment, requests
and limits) and that you have followed the
PromQL lesson, the query
language of Prometheus: rate(), sum by and label filters
are enough. The notions
of cardinality and labels are recalled along the way; the
metrics fundamentals (in French)
detail them if they are new to you.
The 4 Kubernetes observability layers
In Kubernetes, metrics come from 4 different layers. Each layer answers distinct questions, and missing one of them creates blind spots.
| Layer | What it measures | Example questions |
|---|---|---|
| Application | The business behaviour of your code | How many requests? What error rate? What latency? |
| Container | The resource consumption of each container | How much CPU/memory used? Any OOMs? Any throttling? |
| Node | The health of the host machine | Disk full? Network saturated? Kernel panics? |
| Control plane | How Kubernetes itself is running | Is the API server responding? Is the scheduler placing pods? Is etcd healthy? |
Kubernetes does not know your application. The RED metrics (Request rate, Error rate, Duration) or business metrics (orders placed, connected users) must be exposed by your code: the container, node and control plane layers come from the infrastructure, but the application layer is yours to instrument.
The 3 Kubernetes metrics sources
Kubernetes exposes its metrics through 3 distinct components. Each one has a different role, and mixing them up leads to redundant or incomplete dashboards.
On the diagram, look at who is queried and by whom: Prometheus, at the bottom, fetches the metrics of each source with an HTTP request on its endpoint. kube-state-metrics reads the state of objects from the API server, while cAdvisor, built into the kubelet, measures the containers of the node. The three sources are distinct endpoints.
kube-state-metrics: the state of K8s objects
kube-state-metrics (KSM) listens to the Kubernetes API server and converts the state of objects (pods, deployments, nodes, etc.) into Prometheus metrics.
| What it exposes | What it does not do |
|---|---|
| Number of pending, running, failed pods | CPU/memory consumption of containers |
| Desired vs current number of replicas | Host node metrics |
| Reason for the last restart (OOMKilled, Error, etc.) | Application metrics |
| State of PVCs (bound, pending) | Network latency |
| Labels and annotations of K8s objects | Logs |
Example metrics:
kube_pod_status_phase{phase="Pending"}, pods waiting to be scheduledkube_pod_container_status_restarts_total, restart counterkube_pod_container_status_last_terminated_reason{reason="OOMKilled"}, OOMkube_deployment_status_replicas_unavailable, missing replicas
Installation: deploy kube-state-metrics in the kube-system namespace
(official Helm chart) and configure Prometheus to scrape the service; the
guide Prometheus on Kubernetes (in French)
details the deployment with kube-prometheus-stack.
cAdvisor: container resource consumption
cAdvisor (Container Advisor) is built into the kubelet. It measures the real consumption of each container: CPU, memory, network, disk I/O.
| What it exposes | What it does not do |
|---|---|
CPU used per container (container_cpu_usage_seconds_total) | State of K8s objects (replicas, pending) |
Memory used (container_memory_usage_bytes) | Reason for restarts |
Disk I/O (container_fs_reads_bytes_total) | Control plane metrics |
Network per pod (container_network_receive_bytes_total) | Application metrics |
Example metrics:
container_cpu_usage_seconds_total, CPU used (cumulative)container_memory_working_set_bytes, memory usage minus inactive cache (inactive_file)container_cpu_cfs_throttled_periods_totalandcontainer_cpu_cfs_periods_total, the periods in which the CPU limit throttled the container, and the total periods (signal no. 5 explains them)
Prefer container_memory_working_set_bytes over container_memory_usage_bytes
to size your requests and limits: the latter includes the file cache
and inflates the values, whereas working_set removes the inactive cache
(inactive_file) and stays more representative of the memory actually
used. An OOMKilled happens when the container exceeds its memory limit
(cgroup): working_set lets you anticipate this threshold without being the value
the kernel compares.
Kubelet metrics: node health
The kubelet exposes its own metrics about how the node works: pod lifecycle operations, storage, runtime.
| What it exposes | What it does not do |
|---|---|
| Latency of pod operations (start, stop, sync) | Application consumption |
| Runtime (CRI) errors | State of K8s objects |
| Disk space available for pods | Control plane metrics |
| Number of pods per node | Application logs |
Example metrics:
kubelet_pod_start_duration_seconds, pod start timekubelet_volume_stats_available_bytes, available space per PVCkubelet_running_pods, active pods on the node
Scraping in production: auth, TLS and ServiceMonitors
The kubelet endpoints (/metrics, /metrics/cadvisor) run on
port 10250, which is secured (TLS + authentication). In production,
avoid "raw scraping" of node IPs without hardening.
Comparison table of the 3 sources
The column to remember is Deployed by: only kube-state-metrics is a component you
install yourself, the other two are already there as soon as a node joins the cluster. A
classic oversight is therefore to monitor container consumption, available
without installing anything, while staying blind to Pending pods and OOMKilled, which require
deploying KSM.
| Source | Deployed by | Typical endpoint | Main use case |
|---|---|---|---|
| kube-state-metrics | You (Helm/manifest) | kube-state-metrics:8080/metrics | K8s states: pending, OOMKilled, replicas |
| cAdvisor | Built into the kubelet | <node>:10250/metrics/cadvisor | Resource usage: CPU, memory, I/O |
| kubelet | Kubernetes | <node>:10250/metrics | Node health: pod lifecycle, volumes |
The 5 key signals to watch
These 5 signals are the starting point for monitoring a Kubernetes cluster. Each one has a precise metric, a PromQL query and a recommended alert.
1. OOMKilled, the container runs out of memory
Symptom: the pod restarts with no obvious explanation, the application loses its sessions or its in-flight transactions.
Metric: kube_pod_container_status_last_terminated_reason{reason="OOMKilled"}
PromQL query (recently OOMKilled pods, correlated with restarts):
increase(kube_pod_container_status_restarts_total[15m]) > 0and on (namespace, pod, container)kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1The correlation with restarts is necessary: last_terminated_reason
gives the reason for the last stop, so a container OOMKilled
3 days ago that has been running since keeps the value 1 with no recent event. With
increase(restarts), the alert only covers recent OOMs.
Alert:
- alert: ContainerOOMKilled expr: | increase(kube_pod_container_status_restarts_total[15m]) > 0 and on (namespace, pod, container) kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1 for: 0m labels: severity: warning annotations: summary: "Container {{ $labels.container }} in pod {{ $labels.pod }} was OOMKilled (recent)"Actions:
- Check the current memory requests/limits against real consumption
- Investigate memory leaks (profiling, heap dumps)
- Check the GC configuration (Java, Go, Node.js)
- Raise the limits only if the consumption is legitimate: on a memory leak, raising the limit only delays the problem
2. Pod restarts, the crash-restart loop
Symptom: a pod restarts in a loop (CrashLoopBackOff), the application is unstable.
Metric: kube_pod_container_status_restarts_total
PromQL query (pods with > 0 restarts over 15 min):
rate(kube_pod_container_status_restarts_total[15m]) > 0Alert:
- alert: PodCrashLooping expr: rate(kube_pod_container_status_restarts_total[15m]) > 0 for: 5m labels: severity: warning annotations: summary: "Pod {{ $labels.pod }} is crash looping"Actions: examine the logs (kubectl logs --previous), check the
probes (misconfigured liveness/readiness), examine the exit codes.
3. Pending pods, the scheduler cannot place
Symptom: pods stay Pending, deployments do not progress,
the autoscaler does not scale.
Metric: kube_pod_status_phase{phase="Pending"}
PromQL query (pods pending for > 5 min):
sum by (namespace, pod) (kube_pod_status_phase{phase="Pending"}) > 0A Pending pod is sometimes normal during a rollout (image pulls, init
containers, volume mounts): the alert below carries for: 5m to
rule out these short waits. To tell the real causes apart, examine the
pod's Events:
FailedScheduling, insufficient resources, constraints (affinity, taints) or unbound PVC (message "pod has unbound immediate PersistentVolumeClaims");FailedMount, failure to mount or attach a volume on the kubelet side;FailedthenBackOff, image pull failure (image not found or authentication refused); the container then shows theImagePullBackOffstate, which is a waiting state and not an Event.
kubectl describe pod <pod-name> -n <namespace> | grep -A10 EventsAlert:
- alert: PodPendingTooLong expr: sum by (namespace, pod) (kube_pod_status_phase{phase="Pending"}) > 0 for: 5m labels: severity: warning annotations: summary: "Pod {{ $labels.pod }} is pending for more than 5 minutes" runbook_url: "https://example.com/runbooks/pod-pending"Actions: examine the events (kubectl describe pod), check the available
resources (cluster CPU/memory), the constraints
(nodeSelector, affinity, taints/tolerations), the PVCs (pending storage).
4. Node not ready, the node is failing
Symptom: the pods on this node are evicted, they move to other nodes, the cluster capacity decreases.
Metric: kube_node_status_condition{condition="Ready",status="true"}
PromQL query (nodes not ready, with aggregation by node):
sum by (node) (kube_node_status_condition{condition="Ready",status="true"}) == 0Alert:
- alert: NodeNotReady expr: sum by (node) (kube_node_status_condition{condition="Ready",status="true"}) == 0 for: 2m labels: severity: critical annotations: summary: "Node {{ $labels.node }} is not ready"Actions: check the node's network connectivity, the state of the kubelet
(systemctl status kubelet), system resources (disk, memory),
the kubelet logs (journalctl -u kubelet -f).
5. CPU throttling, the container is capped
Symptom: the application is slow, p99 latency rises, but CPU usage looks "normal".
Metrics: container_cpu_cfs_throttled_periods_total and
container_cpu_cfs_periods_total
PromQL query (share of CFS periods throttled, per container):
rate(container_cpu_cfs_throttled_periods_total{container!=""}[5m]) / rate(container_cpu_cfs_periods_total{container!=""}[5m]) > 0.2The kernel enforces the CPU limit in periods of 100 ms by default (this is the CFS quota, CFS being its scheduler). If the container reaches its limit before the end of a period, the kernel suspends its processes until the next one: that period then counts as throttled. The ratio gives the share of throttled periods: 0.43 means that 43% of the periods reached the limit.
These counters only exist for a container that has a CPU limit. The
container!="" filter discards the series aggregated at the Pod level, whose
container label is empty. An idle container has no periods: the ratio is NaN
and the alert does not fire.
Alert:
- alert: ContainerCPUThrottling expr: | rate(container_cpu_cfs_throttled_periods_total{container!=""}[5m]) / rate(container_cpu_cfs_periods_total{container!=""}[5m]) > 0.2 for: 5m labels: severity: warning annotations: summary: "Container {{ $labels.container }} is being CPU throttled"Actions:
- Check the current CPU limits against real consumption
- Raise the CPU limits if the throttling is constant
- For latency-sensitive workloads: consider "requests only"
Kubernetes logs
Metrics tell you that a pod restarts or runs out of memory, logs tell you why. This section covers the two sources to collect: pod logs (container stdout and stderr, with their volume pitfalls) then the logs of the control plane components.
Pod logs: stdout/stderr
In Kubernetes, application logs are the stdout and stderr streams of the containers. The kubelet captures them and stores them on the node.
Collection (the guide Loki with Alloy (in French)
details the full chain): deploy a DaemonSet of collectors (Grafana Alloy,
Fluent Bit, Vector) that reads the /var/log/pods/ files on each
node and sends them to Loki, Elasticsearch, or your logs backend.
Common pitfalls:
| Pitfall | Consequence | Solution |
|---|---|---|
| Logs too voluminous | Storage explodes, high costs | Filter at the source, sample, set short retentions |
| Unstructured logs | Search impossible, fragile parsing | Log in JSON, define a standard schema |
| No K8s labels | Impossible to correlate with metrics/traces | Enrich with pod, namespace, container at collection time |
Control plane logs
The control plane components (API server, scheduler, controller manager,
etcd) write their logs to stdout, visible through kubectl logs in
the kube-system namespace or through journald on the control plane nodes.
| Component | Useful logs | Use case |
|---|---|---|
| kube-apiserver | Slow requests, authentication errors, rate limiting | RBAC debugging, audit, API performance |
| kube-scheduler | Placement failures, reasons for pending | Understand why a pod is not scheduled |
| kube-controller-manager | Reconciliation errors | Debug deployments, replicasets, jobs |
| etcd | Latencies, compactions, leader elections | Diagnose an unstable cluster |
On managed clusters (EKS, GKE, AKS), you often have no access to the control plane logs, or only through an export to your observability stack (Cloud Logging, CloudWatch). On self-hosted clusters, configure the collection explicitly.
The cardinality trap
Kubernetes generates dynamic labels: pod, container, uid,
revision, node. These labels change with every recreated Pod
(rollout, eviction, scaling). The result: your cardinality explodes.
The problem
Prometheus stores each unique combination of metric + labels as a time series (the governance (in French) guide details the costs of cardinality and retention). The number of series is the product of the number of values of each label.
Catastrophic example:
container_cpu_usage_seconds_total{ namespace="production", pod="payment-api-abc123", container="payment", node="node-1"}With 50 pods × 20 containers × 10 nodes, a single metric already has
thousands of combinations. cAdvisor exposes dozens of metrics per
container, and every rolling update creates new pod values:
you quickly reach millions of series, and Prometheus collapses.
Dangerous labels
The classification criterion is not the number of values at a given moment, but the speed at
which new values appear. A node label stays stable for months; a
pod label changes with every recreated Pod (rollout, eviction, scaling), and every vanished value leaves behind an
inactive series that Prometheus keeps until the retention expires. This phenomenon, called
churn, is what drives memory consumption up long before the number of live pods
looks worrying.
| Label | Typical cardinality | Risk |
|---|---|---|
pod | Unlimited (changes with every recreated Pod) | Very high |
uid | Unlimited (unique per object) | Very high |
container_id | Unlimited | Very high |
id | Unlimited (cgroup id) | Very high |
name | Potentially unlimited | Very high |
image | High (changes with every tag) | Medium-high |
revision | Potentially high | Medium |
node | Number of nodes (often < 100) | Low |
namespace | Number of namespaces (often < 50) | Low |
How to protect yourself
Principle: first remove the series that make no sense (system
cgroups, with no pod label), then the very high
cardinality labels. Only drop an entire metric if you know you do not
use it (after auditing dashboards, alerts, recording rules).
1. Filter the explosive labels at scrape time (metric_relabel_configs):
scrape_configs: - job_name: 'cadvisor' metric_relabel_configs: # First: discard the series with no container or pod (system # cgroups), which labeldrop would make identical - source_labels: [container, pod] regex: ';' action: drop # Then: remove the labels with unlimited cardinality - action: labeldrop regex: 'id|name|image|container_id|uid'The drop comes before the labeldrop for a precise reason. On cAdvisor, the
id label (cgroup path) is the only difference between many series with no
pod label, such as the system cgroups / or /system.slice. Once id is
removed, these series become identical. The first rule therefore discards the
series where container and pod are both empty: the ; regex matches the two
empty values joined by ;. Testing pod as well avoids losing the per-pod
network metrics, whose container label can be empty or absent.
This drop targets precise series, never entire metrics. Avoid
dropping a complete metric before auditing its usage: an
action: drop on container_cpu.* would make you lose exactly the
metrics that the alerts of this page need.
2. Use bounded labels:
deployment,statefulsetinstead ofpodnamespace,serviceinstead ofcontainer_id- Normalise paths:
/users/12345→/users/:id
3. Monitor your cardinality:
# Top 10 metrics by number of seriestopk(10, count by (__name__) ({__name__!=""}))
# Series per label for a metriccount by (pod) (container_cpu_usage_seconds_total)4. Alert on growth:
- alert: HighCardinalityMetric expr: count by (__name__) ({__name__=~"container_.*"}) > 100000 for: 5m labels: severity: warning annotations: summary: "Metric {{ $labels.__name__ }} has very high cardinality"Noisy neighbors: detecting workloads that over-consume
In a multi-tenant cluster, a workload can consume all the resources of a node and degrade the performance of the other pods, this is the "noisy neighbor problem".
Symptoms
What characterises a noisy neighbor is that the symptoms appear on workloads that
changed nothing. A deployment whose latency degrades with no new release or traffic
increase should make you look at its neighbours on the node, not at its own code. The
cross-check is done with the node label: list the other pods of the same node over the
incident window.
- p99 latency rising on "innocent" pods
- CPU throttling on pods that should not have any
- Pod evictions for memory pressure
- Pods that can no longer be scheduled (resources exhausted)
Detection metrics
The three queries below answer three distinct questions: who consumes, how much, and
who is not bounded. Note the container!="" filter: cAdvisor metrics include an
aggregated series for the pod sandbox, whose container label is empty. Without this filter, you
count the consumption twice.
CPU per namespace (share of the total cluster consumption):
sum by (namespace) ( rate(container_cpu_usage_seconds_total{container!=""}[5m]))/ ignoring(namespace) group_leftsum(rate(container_cpu_usage_seconds_total{container!=""}[5m]))Memory per namespace:
sum by (namespace) (container_memory_working_set_bytes{container!=""})Containers without a CPU limit (noisy neighbor candidates):
count by (namespace, pod, container) (kube_pod_container_info)unless on (namespace, pod, container)kube_pod_container_resource_limits{resource="cpu"}Protection
These four mechanisms act at different moments of a pod's life, and they combine. Limit Ranges step in at admission by injecting default values, which addresses the root of the problem: a container without a limit. Resource Quotas cap the cumulative consumption of a namespace. Priority Classes only come into play under pressure, to decide who is evicted first. Start with Limit Ranges, it is the only one that prevents the problem from appearing. Pod Disruption Budgets complete the picture without dealing with the noisy neighbor: they guarantee a minimum of replicas during voluntary evictions (draining a node), but not during an eviction triggered by resource pressure on the node.
| Method | Description | When to use it |
|---|---|---|
| Resource Quotas | Per-namespace limits (total CPU/memory) | Multi-tenant |
| Limit Ranges | Defaults and limits per pod/container | Prevent pods without limits |
| Priority Classes | Ordered eviction under pressure | Protect critical workloads |
| Pod Disruption Budgets | Guarantee a minimum of replicas | High availability |
8 essential alerts for a K8s cluster
Here is a minimal set of alerts ready for production, which covers the critical signals without excessive noise. Their writing follows the principles of Effective alerting (in French), and they reuse the five signals above plus three capacity alerts (memory close to the limit, missing replicas, pending PVC).
Two conventions structure the block and are worth keeping as they are.
First the severity: only NodeNotReady is critical, because it is
the only event that reduces cluster capacity with no possible action from
the application. Then the runbook_url annotation, present on every
rule: an alert without an associated procedure
ends up ignored, and it is the runbook that turns a notification into an
action. Replace the example.com domain with that of your own knowledge
base.
groups: - name: kubernetes-essential rules: # 1. Pod OOMKilled (recent event) - alert: ContainerOOMKilled expr: | increase(kube_pod_container_status_restarts_total[15m]) > 0 and on (namespace, pod, container) kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1 for: 0m labels: severity: warning annotations: summary: "Container {{ $labels.container }} was OOMKilled (recent)" runbook_url: "https://example.com/runbooks/oomkilled"
# 2. Pod crash looping - alert: PodCrashLooping expr: rate(kube_pod_container_status_restarts_total[15m]) > 0 for: 5m labels: severity: warning annotations: summary: "Pod {{ $labels.pod }} is crash looping" runbook_url: "https://example.com/runbooks/crashloop"
# 3. Pod pending - alert: PodPendingTooLong expr: sum by (namespace, pod) (kube_pod_status_phase{phase="Pending"}) > 0 for: 5m labels: severity: warning annotations: summary: "Pod {{ $labels.pod }} is pending" runbook_url: "https://example.com/runbooks/pod-pending"
# 4. Node not ready - alert: NodeNotReady expr: sum by (node) (kube_node_status_condition{condition="Ready",status="true"}) == 0 for: 2m labels: severity: critical annotations: summary: "Node {{ $labels.node }} is not ready" runbook_url: "https://example.com/runbooks/node-not-ready"
# 5. CPU throttling - alert: ContainerCPUThrottling expr: | rate(container_cpu_cfs_throttled_periods_total{container!=""}[5m]) / rate(container_cpu_cfs_periods_total{container!=""}[5m]) > 0.2 for: 5m labels: severity: warning annotations: summary: "Container {{ $labels.container }} is CPU throttled" runbook_url: "https://example.com/runbooks/cpu-throttling"
# 6. Memory close to the limit # The "> 0" filter discards containers without a limit, whose # container_spec_memory_limit_bytes is 0 (division by zero). - alert: ContainerMemoryNearLimit expr: | container_memory_working_set_bytes{container!=""} / (container_spec_memory_limit_bytes{container!=""} > 0) > 0.9 for: 5m labels: severity: warning annotations: summary: "Container {{ $labels.container }} memory at 90%+ of limit" runbook_url: "https://example.com/runbooks/memory-near-limit"
# 7. Deployment replicas mismatch - alert: DeploymentReplicasMismatch expr: | kube_deployment_spec_replicas != kube_deployment_status_replicas_available for: 5m labels: severity: warning annotations: summary: "Deployment {{ $labels.deployment }} replicas mismatch" runbook_url: "https://example.com/runbooks/replicas-mismatch"
# 8. PVC pending - alert: PersistentVolumeClaimPending expr: kube_persistentvolumeclaim_status_phase{phase="Pending"} == 1 for: 5m labels: severity: warning annotations: summary: "PVC {{ $labels.persistentvolumeclaim }} is pending" runbook_url: "https://example.com/runbooks/pvc-pending"Anti-patterns: what not to do
Two families emerge from the table below. The collection and storage
anti-patterns (pod label, whole cAdvisor metrics, per-pod dashboards, logs
at debug level or with no retention limit) cost money and
stability: a saturated Prometheus, a growing bill, and nobody to
say which series are really used. The coverage anti-patterns
(no kube-state-metrics, alerts on containers only, logs without labels,
control plane ignored) cost incident time: the monitoring runs,
but it does not answer the questions you ask at three in the morning. These
defects are not visible at creation: an overly broad scrape does not bother a
cluster of ten pods, it brings Prometheus down when it has three hundred.
So watch the trend (active series, daily log volume) rather than
today's value.
If you only fix one point, pick "No kube-state-metrics": without it, four of the five key signals are no longer observable (only CPU throttling comes from cAdvisor).
| Anti-pattern | Why it is a problem | Solution |
|---|---|---|
Scraping pod as a label | Cardinality explodes with every deploy | Aggregate by deployment, service |
| Collecting all cAdvisor metrics | Hundreds of series per container | Filter at scrape time (labeldrop on explosive labels) |
| No kube-state-metrics | Impossible to see pending, OOMKilled, replicas | Deploy KSM from day one |
| Alerts on container metrics only | Misses the K8s context (rollout, scaling) | Combine with kube-state-metrics |
| Logs without K8s labels | Impossible to correlate with metrics/traces | Enrich with namespace, pod, container |
| Ignoring the control plane | API server, scheduler problems invisible | Collect the control plane metrics |
| No resource quotas | One namespace can kill the cluster | Resource quotas in multi-tenant |
| CPU limits too low | Artificial throttling, degraded latency | Consider requests-only for sensitive workloads |
| Per-pod dashboards | 200 pods = unreadable dashboard | Aggregate by deployment, namespace, service |
| Unlimited log retention | Costs explode | Short retention (7-30 days), cold tier |
| Debug-level logs in production | Volume and costs multiplied | Info or warn level in production |
Workflow: deploy observability on a K8s cluster
The order of these eight steps is not arbitrary. Cardinality filtering comes as early as step 2, before the dashboards and alerts, because high-cardinality series ingested before the filtering stay in memory and on disk until the retention expires: the filter erases nothing, it only stops ingesting. Conversely, resource quotas come late: they assume you know the real consumption of each namespace, information that only the previous steps give you. Treat steps 7 and 8 as recurring work, not as a one-off setup.
-
Deploy kube-state-metrics
Official Helm chart or manifest. Check that the service is scraped by Prometheus. You should see the
kube_*metrics. -
Configure cAdvisor / kubelet scraping with ServiceMonitors
Use the ServiceMonitors/PodMonitors of your stack (kube-prometheus-stack). Configure RBAC and TLS certificates. Add
metric_relabel_configsto filter the dangerous labels (id,name,image,container_id,uid), watching out for the collisions described above. -
Deploy a log collector
Grafana Alloy, Fluent Bit or Vector as a DaemonSet; Promtail has been end-of-life since March 2026 and must no longer be chosen for a new deployment. Configure the enrichment with the K8s labels (
namespace,pod,container) and the shipping to Loki or your backend. -
Create the base dashboards
A Cluster overview dashboard (nodes, pending pods, restarts), built with the method of useful dashboards (in French). A Namespace dashboard (CPU/memory per deployment, top consumers). A Pod debugging dashboard (logs + metrics for investigation).
-
Deploy the 8 essential alerts
PrometheusRule with the OOMKilled, crash loop, pending, node not ready, throttling, memory near limit, replicas mismatch, PVC pending alerts. Add the
runbook_urlannotations pointing to your runbooks. -
Configure resource quotas (multi-tenant clusters)
Per-namespace limits for CPU and memory. Limit ranges for the pod defaults.
-
Monitor your cardinality
Dedicated dashboard: top metrics by series, growth over time. Alert if a metric exceeds a threshold.
-
Iterate on the filters and aggregations
Every week, identify unused metrics and redundant labels. Refine your recording rules to pre-aggregate.
Sources
Official references on the metrics and endpoints described above.
- Kubernetes, Monitoring overview: kubernetes.io/docs/tasks/debug/monitoring, the official reference on K8s monitoring
- Kubernetes, System components metrics: kubernetes.io/docs/concepts/cluster-administration/system-metrics, documentation of the kubelet and cAdvisor endpoints, and control plane metrics
- kube-state-metrics, GitHub: github.com/kubernetes/kube-state-metrics, documentation and exhaustive list of the exposed metrics
- Robust Perception, Cardinality is key: robustperception.io/cardinality-is-key, Brian Brazil on Prometheus cardinality
- Kubernetes, kubelet reference: kubernetes.io/docs/reference/command-line-tools-reference/kubelet, kubelet reference including the CFS quota and throttling aspects
Put it into practice
In the lab, Prometheus already collects the cluster's three metric sources: kube-state-metrics, the kubelet and cAdvisor. It has no alert rule yet. In the signaux namespace, the memoire-courte Pod is killed regularly because it exceeds its memory limit, and calcul-serre is throttled all the time by its CPU limit. A third Pod, temoin-calme, also has limits but never reaches them.
You write two alerts, SignauxOOMKilled and SignauxThrottling, from the queries of signals 1 and 5 on this page. Prometheus reads its rules from the prometheus-regles ConfigMap in the supervision namespace, in the groups format shown in the section on the 8 alerts. It only picks them up after a reload, and an alert stays pending for the duration of its for: before moving to firing.
Validation queries the Prometheus API: it reads the firing alerts and checks that SignauxOOMKilled targets memoire-courte, that SignauxThrottling targets calcul-serre, and that neither targets temoin-calme. Wait until both of your alerts are firing before running the check.
Key points
-
Kubernetes exposes metrics at 4 layers: application (you instrument it), container (cAdvisor), node (kubelet), control plane (API server, scheduler, etcd)
-
The 3 main sources: kube-state-metrics for the K8s state (pending, OOMKilled, replicas), cAdvisor for resource consumption (CPU, memory, I/O), kubelet for node health
-
The 5 key signals: OOMKilled (memory exceeded), pod restarts (crash loop), lasting Pending pods (scheduler blocked, volume or image), node not ready (failing node), CPU throttling (share of the CFS periods in which the CPU limit throttled the container)
-
Cardinality explodes with dynamic labels (
pod,uid,container_id). Filter at scrape time withlabeldrop, aggregate bydeploymentorservice, monitor with dedicated PromQL queries -
Noisy neighbors are detected by comparing consumption per namespace/deployment. Protect yourself with resource quotas and limit ranges
-
K8s logs are the stdout/stderr of the pods. Enrich them with the K8s labels at collection time, limit the volume with short retentions
-
For the control plane (self-hosted clusters), collect the metrics of the API server, scheduler, controller manager, etcd. On managed clusters, use the provider's integration
-
Start with 8 essential alerts: OOMKilled (event-based), crash loop, pending, node not ready, throttling, memory near limit, replicas mismatch, PVC pending
Knowledge check
Check that you have the essentials of this guide. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Kubernetes Incident Diagnosis Method
A new full quiz with random questions
Work again only on the questions you missed