1) Inspect kubelet metrics (via kubectl proxy)
Each kubelet exposes Prometheus-format (OpenMetrics) metrics on the node, but the endpoint is authenticated. Usekubectl to proxy through the API server and save a node’s kubelet metrics locally:
2) Inspect kube-apiserver metrics
The kube-apiserver exposes a high-cardinality, comprehensive metrics set. Fetch it usingkubectl:
3) Prometheus metric patterns and histograms
Prometheus histogram exposition generates multiple series per logical histogram:<metric>_bucket{le="..."} ...— counts up to each bucket bound<metric>_sum— total sum of all observations<metric>_count— total observation count
histogram_quantile() over an aggregated sum by (le) ( rate(..._bucket[range]) ).
Use the PromQL
rate() (or increase()) function for counter metrics (cumulative counters). For latency percentiles from histograms use histogram_quantile() with an aggregated *_bucket time rate.4) Deploy kube-prometheus-stack with Helm
The community kube-prometheus-stack Helm chart packages Prometheus Operator, Prometheus, Alertmanager, Grafana, kube-state-metrics, and default ServiceMonitors. Install it to get a production-oriented stack quickly. Add the Helm repo and update:values.yaml to control retention, scrape intervals, resources, and which ServiceMonitors to enable. Example values.yaml excerpt:
5) Query metrics in Grafana Explore / Prometheus
Open Grafana (via port-forward or your configured ingress) and use Explore (compass icon) for ad-hoc PromQL queries. Useful queries:- Rate of API server requests (per second over 5 minutes):
- Filter for successful HTTP 2xx responses (regex on
codelabel):
- Aggregate rate by HTTP verb:
rate()? Counters are cumulative; rate() returns a per-second average over the window and is appropriate for dashboards and alerts.
6) Histograms and percentiles (P50, P95, P99)
Calculate percentiles from histogram buckets withhistogram_quantile():
Template:
- A value of
0.05indicates 99% of requests completed within 0.05 seconds (50 ms). - Use
histogram_quantile(0.5, ...)for P50 (median). - Always aggregate buckets (
sum by (le)) across series before applyinghistogram_quantile().
7) Counters vs. Histograms vs. Gauges
Use this quick reference for metric types and how to query them:8) Exercise: Top containers by memory in the monitoring namespace
List the top 5 containers by working set memory (GB) in themonitoring namespace:
namespace/pod/container combinations by memory (in GB). Typical top consumers in a monitoring namespace include:
- Grafana (main container)
- Grafana sidecar (dashboards/datasources)
- Prometheus server
- kube-state-metrics
- Prometheus keeps in-memory indexes and recent time-series; more targets → higher memory.
- Grafana and sidecars load dashboards and datasources into memory.
- Sidecars may maintain caches and also consume memory.
Final notes and tuning guidance
- Tune Prometheus retention, scrape intervals, and target selection to balance observability needs and resource/cost constraints.
- Use
rate()for counters,histogram_quantile()for histogram percentiles, and raw values/aggregations for gauges. - The kube-prometheus-stack Helm chart simplifies deployment and includes many pre-built dashboards and ServiceMonitors that mirror the metrics you inspected manually.
Links and references
- Prometheus documentation
- Grafana documentation
- kube-prometheus-stack Helm chart (prometheus-community)
- Kubernetes metrics & API docs
- Helm documentation