Prometheus stores 15 days of metrics by default. After that, data is gone. Thanos uploads Prometheus blocks to object storage and lets you query years of metrics across multiple clusters from a single endpoint.
Architecture
Cluster A: Prometheus + Thanos Sidecar → S3
Cluster B: Prometheus + Thanos Sidecar → S3
↓
Thanos Store Gateway
↓
Thanos Querier ← Grafana- Sidecar: Runs alongside Prometheus, uploads blocks to S3
- Store Gateway: Reads blocks from S3 for historical queries
- Querier: Unified query endpoint across all Prometheus instances and Store Gateways
- Compactor: Downsamples and compacts historical data
Thanos Sidecar
# Add sidecar to existing Prometheus
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: prometheus
spec:
template:
spec:
containers:
- name: prometheus
image: prom/prometheus:v2.51.0
args:
- --storage.tsdb.min-block-duration=2h
- --storage.tsdb.max-block-duration=2h
volumeMounts:
- name: data
mountPath: /prometheus
- name: thanos-sidecar
image: quay.io/thanos/thanos:v0.35.0
args:
- sidecar
- --tsdb.path=/prometheus
- --objstore.config-file=/etc/thanos/objstore.yaml
volumeMounts:
- name: data
mountPath: /prometheus
- name: thanos-config
mountPath: /etc/thanos# objstore.yaml
type: S3
config:
bucket: my-thanos-metrics
region: eu-west-1
endpoint: s3.eu-west-1.amazonaws.comThe sidecar uploads completed 2-hour blocks to S3. Prometheus continues to serve recent queries from local storage.
Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Thanos Querier
apiVersion: apps/v1
kind: Deployment
metadata:
name: thanos-querier
spec:
template:
spec:
containers:
- name: querier
image: quay.io/thanos/thanos:v0.35.0
args:
- query
- --store=thanos-sidecar-cluster-a:10901
- --store=thanos-sidecar-cluster-b:10901
- --store=thanos-store-gateway:10901
ports:
- containerPort: 9090 # PromQL endpointPoint Grafana at the Querier. Every PromQL query automatically fans out to all connected stores and deduplicates results.
Store Gateway
Serves historical data from object storage:
containers:
- name: store-gateway
image: quay.io/thanos/thanos:v0.35.0
args:
- store
- --objstore.config-file=/etc/thanos/objstore.yaml
- --data-dir=/var/thanos/storeWhen you query metrics from 6 months ago, the Store Gateway reads blocks from S3. Recent data comes from Prometheus via the Sidecar.
Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Compactor
Downsamples historical data to reduce storage costs:
containers:
- name: compactor
image: quay.io/thanos/thanos:v0.35.0
args:
- compact
- --objstore.config-file=/etc/thanos/objstore.yaml
- --data-dir=/var/thanos/compact
- --retention.resolution-raw=30d
- --retention.resolution-5m=180d
- --retention.resolution-1h=365d- Raw data (5s resolution): kept 30 days
- 5-minute downsampled: kept 180 days
- 1-hour downsampled: kept 1 year
A year of metrics from 100 services costs a few dollars in S3.
Multi-Cluster Querying
Grafana → Thanos Querier → [Sidecar A, Sidecar B, Sidecar C, Store Gateway]# CPU usage across ALL clusters
sum(rate(container_cpu_usage_seconds_total{namespace="production"}[5m])) by (cluster)One query, all clusters. The Querier deduplicates metrics from HA Prometheus pairs.
Thanos vs Alternatives
| Feature | Thanos | Cortex/Mimir | VictoriaMetrics |
|---|---|---|---|
| Architecture | Sidecar + components | Write-ahead (remote write) | Standalone or cluster |
| Prometheus compatibility | Full (reads TSDB blocks) | Full (remote write) | Full (remote write) |
| Multi-cluster | Global query | Global query | Global query |
| Storage | S3/GCS/Azure | S3/GCS/Azure | Local + S3 |
| Operational complexity | Medium | High | Low |
| Downsampling | Built-in | Via recording rules | Built-in |
Choose Thanos for sidecar-based approach with minimal Prometheus changes. Choose Mimir for high-ingest workloads needing write-ahead architecture. Choose VictoriaMetrics for simplicity and performance.
---
Ready to go deeper? Build your monitoring stack with hands-on courses at CopyPasteLearn.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Grafana Mimir Scalable Metrics Store
Grafana Mimir stores Prometheus metrics at massive scale using object storage. Learn how Mimir compares to Thanos and Cortex, and how to deploy it.
Prometheus Monitoring Beginner Guide
Get started with Prometheus monitoring. Metrics collection, PromQL queries, Grafana dashboards, and alert configuration step by step.
Grafana Dashboard Best Practices
Build effective Grafana dashboards for monitoring. Layout patterns, template variables, alert integration, and dashboard-as-code.
Tilt Kubernetes Dev Environment
Tilt automates the build-push-deploy loop for Kubernetes development. Learn how Tilt watches code changes, rebuilds containers, and updates deployments.
Traefik Kubernetes Ingress Guide
Traefik is a cloud-native reverse proxy and ingress controller for Kubernetes. Learn how to configure routing, TLS termination, middlewares, and canary.
Trivy Container Vulnerability Scanner
Trivy scans container images, filesystems, and IaC for vulnerabilities and misconfigurations. Learn how to integrate Trivy into your CI/CD pipeline.
Explore topics
Browse more articles on the topics covered here.