Long-term Kubernetes metrics with Thanos

Thanos adds long-term storage, a global query view and downsampling on top of Prometheus. This page explains when to use the sidecar or Receive, what the design requires and what to confirm before building it.

On this page

Long-term Kubernetes metrics with Thanos: when a single Prometheus is not enough

A single Prometheus keeps local data for a limited window, and it is not clustered or replicated. Its default retention is 15 days, configurable by time or size, and its local storage behaves like any other single-node database. If a cluster's Prometheus server fails, the history it held is only as safe as the disk and backups you put under it. Teams usually reach the limit in one of three ways: they need incident reviews and capacity trends that go back months, they run several clusters and want one place to query them, or they run highly available Prometheus pairs and need the duplicate series merged before anyone reads a graph.

Thanos adds those capabilities on top of existing Prometheus deployments. It provides a global query view across connected Prometheus servers, deduplication of HA pairs, downsampling of historical data, cross-cluster federation, and long-term retention in any object storage, which is its only optional dependency. The project is licensed under Apache-2.0 and is a CNCF Incubating project. Thanos needs one or more Prometheus v2.2.1 or later installations with persistent disk, plus object storage if you want retention beyond local disk. It is built to run as a distributed system and is not recommended on a single node, so plan for at least the components that carry your query path and your data path to run on separate, recoverable infrastructure.

Decide early whether you need Thanos at all. If one cluster and a retention window of a few weeks cover your needs, a larger local disk, a well-tuned kube-prometheus-stack deployment and an external backup may be enough. If you need months of history, cross-cluster queries or HA deduplication, Thanos is the usual next step. Before you commit, confirm the object storage you will use, the retention you need per resolution, the team that will own the compactor and store gateway, and how you will restore the bucket if it is lost. The Thanos getting started guide is the natural next read for the component layout.

Sidecar or Receive: choosing how metrics reach Thanos

The sidecar pattern keeps each Prometheus server as the place where metrics are scraped and stored for its first hours. A Thanos Sidecar runs next to each Prometheus instance, implements the Thanos Store API on top of the Prometheus remote-read API, and uploads TSDB blocks to object storage as Prometheus produces them every 2 hours. This fits teams that already run Prometheus per cluster and want to add long-term storage and a global query view without changing how targets are scraped.

  • Scraping stays local: Prometheus keeps its existing scrape configuration, service discovery and rule evaluation, so existing dashboards and alerts need little rework.
  • Block upload settings are mandatory: Prometheus min and max block duration must be set to equal values to disable local compaction, because the Thanos Sidecar docs say otherwise uploaded data can be corrupted.
  • Query path depends on Prometheus: recent data is served by the Prometheus instance itself, so a failed Prometheus affects both scraping and the recent window of queries.
  • Each cluster needs local disk: Prometheus still requires persistent disk, and its local retention setting should be sized for the gap before blocks are uploaded and read back.
  • Operations split across sites: each Prometheus and sidecar pair is upgraded and monitored separately, so version alignment becomes a checklist item.

Before adopting this pattern, confirm the Prometheus version against the Thanos release you plan to run and check that your Prometheus Operator or Helm values set the block duration fields explicitly.

How Thanos components connect to Prometheus and object storage

The diagram starts with two ways data leaves a cluster: the Thanos sidecar beside each Prometheus server, and Prometheus remote write into Thanos Receive. Both paths end in one object storage bucket. The Compactor is the only component that works on that bucket as a singleton, so it is the hand-off to check first. On the query side, Thanos Query reads live data and bucket data through the Store Gateway, and Query Frontend sits in front of it. Confirm that each cluster's data reaches exactly one path.

Data paths from Prometheus into object storage and the central query layer.

Thanos components and when each fits

This table compares the Thanos components named in the topic research, showing the role of each, when a design needs it and the main operational note. Read it by first choosing a sidecar or receive ingestion path, then adding query, storage and maintenance components only as your cluster count and retention needs require.

ComponentRole and when it is neededMain operational note
SidecarRuns beside each Prometheus, implements the Store API over remote read and uploads TSDB blocks every 2 hours. Needed when Prometheus stays the scrape point.Set Prometheus min and max block duration to equal values, or local compaction can corrupt uploaded data.
Query (Querier)Provides the global query view across connected Prometheus, Sidecar and Store endpoints. Needed for any multi-cluster or long-range view.Deduplicates HA Prometheus pairs; confirm which replica labels your design uses before building dashboards on it.
Query FrontendOptional layer in front of Query that improves query handling for dashboards. Add it when many users or large dashboards load Query.Optional, not required for correctness; confirm its caching and splitting settings against your query volume.
Store (store gateway)Serves historical blocks from object storage to Query. Needed when you keep data beyond what local Prometheus retains.Sizing depends on the object storage bucket size and query load; monitor memory and response latency.
ReceiveImplements the Prometheus Remote Write API so Prometheus pushes samples and uploads blocks every 2 hours by default. Used instead of Sidecar when a central ingestion path is preferred.Tenants are identified by the THANOS-TENANT header by default; plan tenant labels before rollout.
RuleEvaluates recording and alerting rules against the global view across clusters. Optional, needed only when rules must span clusters.Rules evaluated against Thanos data depend on query and store availability; keep per-cluster alerting in Prometheus.
CompactCompacts blocks and downsamples raw data older than 40 hours to 5-minute resolution, then 5-minute data older than 10 days to 1-hour resolution. Needed for long retention with lower-resolution history.Must run as a singleton against each object storage bucket; never run two compactors on the same bucket.

How to set up Thanos on an existing Prometheus deployment

This sequence takes a working Prometheus setup and adds Thanos for object storage backed retention, a global query view and downsampled history, while keeping local Prometheus behavior predictable. Each step ends with a check you can run before moving on.

  1. Confirm Prometheus version and persistent disk

    The platform team checks that every Prometheus server in scope runs version 2.2.1 or later, that each one writes to a persistent disk, and that the Prometheus instances you plan to connect are the ones that hold the data you want to keep. Record the version, the storage class or volume, and the configured local retention for each server. Done means every server reports a supported version in its status page, its data directory sits on persistent storage, and you have a written inventory of which clusters and HA pairs will be joined. Confirm with your own environment's Prometheus Operator or Helm values, since those control how the server is run.

  2. Set matching min and max block duration

    For sidecar uploads, the platform team sets Prometheus min and max block duration to the same value so local compaction is disabled. The Thanos sidecar documentation warns that leaving them unequal can corrupt uploaded data. Apply the change through your Prometheus configuration or the Prometheus Operator custom resource, then restart the rollout under change control. Verification: after the restart, check the running configuration on each server and confirm both flags report the same value. Keep this in your change record, because it affects how Prometheus stores data for every future upgrade.

  3. Provision object storage bucket and credentials

    The platform team creates one object storage bucket for each set of Thanos data that will be queried together, plus a dedicated service identity with the narrowest access that lets the sidecar or Receive write blocks and lets Store Gateway, Compactor and Query read them. Store the credentials in your secrets system, not in plain values files. Confirm with your storage provider how access keys are rotated and whether bucket versioning or lifecycle rules are available. Verification: a test upload and read with the new identity succeeds, and a delete attempt from the read-only identity is refused.

  4. Deploy the sidecar or Receive

    Choose the sidecar for Prometheus servers you already run and want to keep as the scrape path. Choose Receive when Prometheus should push samples over remote write into a central tenant-aware component. Deploy the sidecar next to each Prometheus pod, or deploy Receive with its tenant configuration and point Prometheus remote write at it. Verification: the sidecar logs show a successful connection to Prometheus and an object storage client, and after the first two-hour block is cut, the block directory appears in the bucket. For Receive, confirm the tenant header is set and data arrives under the expected tenant.

  5. Deploy Store Gateway and Query

    Deploy the Store Gateway so historical blocks in the bucket can be read, then deploy Query and point it at the sidecars or Receive and at the Store Gateway. Query merges results from live Prometheus data and stored blocks, and it deduplicates HA pairs when replica labels are configured consistently. Verification: in the Query UI, run a simple series query for a known metric and confirm the stores listed include the sidecars and the gateway. Then run a query over a time range older than your local Prometheus retention and confirm it returns data from the bucket.

  6. Run the Compactor as a single instance per bucket

    Deploy the Compactor so it runs as one instance per object storage bucket, and do not let a second instance run against the same bucket, because the Thanos compactor documentation requires it to run as a singleton. Confirm the replica count is one in your deployment and that any restart policy does not start a replacement while the old pod is still active. Verification: the Compactor logs show it scanning the bucket and completing compaction without errors, and the block count in the bucket decreases over time as smaller blocks merge.

  7. Configure downsampling and retention

    Enable downsampling through the Compactor settings and set retention for raw, 5-minute and 1-hour resolution data according to your requirements. The Thanos compactor documentation says raw data older than 40 hours is downsampled to 5-minute resolution, and 5-minute data older than 10 days is downsampled to 1-hour resolution. Decide the retention for each resolution with your compliance and capacity owners before applying it, since deleted resolutions cannot be recovered. Verification: after a downsampling pass completes, run the same query at a long time range with auto step and confirm the Query UI reads from the lower resolution data, and confirm the bucket holds blocks labeled for each resolution.

How compaction and downsampling shape query cost and retention

The Thanos Compactor decides how much of your history stays at full resolution, and it has to run as a singleton against each object storage bucket. The Compactor downsamples raw data older than 40 hours to 5-minute resolution, then downsamples 5-minute data older than 10 days to 1-hour resolution. Those two thresholds mean that a query over last week reads raw samples, while a query over last year reads hourly points. Before you go live, decide which bucket each cluster or tenant writes to, then run exactly one Compactor per bucket. Two Compactors against the same bucket can compact the same blocks concurrently, so treat the singleton rule as a deployment constraint, not a tuning choice, and confirm how your platform restarts and schedules that workload.

Compaction also drives storage growth and the cost of queries over months. Raw blocks are written by the Sidecar or Receive as Prometheus produces them, and downsampled copies sit alongside them in the same bucket, so object storage usage grows with both raw retention and the downsampled series. Query cost follows the same pattern: a wide range over raw data scans many more samples than the same range at 1-hour resolution. Ask your team to list the dashboards, alert queries and capacity reports that look back more than a few weeks, and check which of them need exact values. Confirm the raw and downsampled retention you plan to keep with the Thanos Store and Compactor settings in your own environment, and confirm how long you must keep raw data for audit or incident review before you tune anything else.

Downsampling changes what older queries return, and that affects anyone who compares old numbers with new ones. A 1-hour point is an aggregate of the underlying samples, so spikes shorter than the window can disappear from long-range graphs, and an alert rule that depends on short-lived peaks should not be evaluated against downsampled history. Document which resolution users see at each time range and add that note to your dashboards and runbooks. Then test a known incident window at raw and downsampled resolution before you rely on long-range data for post-incident analysis. Retention targets should come from the questions your teams actually ask of the data, and you should confirm them with those owners rather than adopting a default.

Security and operational considerations for Thanos

Thanos moves your metrics into object storage and exposes them through query endpoints, so the security work spans the bucket, the network paths to it and the Prometheus targets feeding it. Each card below is a control point to design before the first block is uploaded, and each ends with what to confirm in your own environment.

Object storage credentials and bucket policy

Every Thanos component that writes or reads blocks needs credentials for the bucket, and the sidecar, Receive, Store, Compact and Rule components each hold a copy. Give each component its own identity with only the permissions it needs, and deny delete access to everything except the compactor's retention work. Confirm how your object store issues and rotates those keys, and whether bucket versioning or object lock is available for your retention requirements.

Compactor docs

Encryption and access to query endpoints

The Query and Query Frontend endpoints serve every connected cluster's metrics to anyone who can reach them, so they need transport encryption and authentication in front of them. Thanos does not replace an identity layer, so place the endpoints behind your reverse proxy or service mesh with TLS and SSO. Confirm which Thanos flags your version supports for TLS on each gRPC and HTTP listener before you expose anything beyond the cluster network.

Tenant isolation with Receive

Thanos Receive identifies tenants by the THANOS-TENANT header by default, so the header value decides which tenant's data a write lands in. Any client that can reach the Receive endpoint can set that header, which means tenant separation depends on your ingress authentication and on Prometheus remote write configuration that stamps the header correctly. Test that a cluster cannot write to or read another tenant's series, and confirm the tenant header handling in the Receive version you deploy.

Receive docs

Prometheus security model and metric exposure

Prometheus is designed to run on a trusted network: it pulls metrics over HTTP and its own query API has no built-in authentication. Metrics often carry hostnames, pod names, label values and sometimes sensitive application data, so decide which endpoints the sidecar and remote read paths expose and who can reach them. Review the Prometheus security model page with your security team and confirm which labels you drop or relabel before data reaches object storage.

Prometheus security model

Singleton compactor operation

The compactor must run as a singleton against each object storage bucket, so two compactors pointed at the same bucket can corrupt the downsampling and retention work. Schedule it with a deployment that cannot scale out, add alerting for restarts or missed runs, and make sure a replacement pod cannot start while the previous one is still working. Confirm how your platform enforces a single replica and what happens to downsampled data if the compactor is paused for a long period.

Compactor per bucket
1

Backup and recovery of the bucket

Object storage holds your only long-term copy of historical metrics, and a bad compaction run, accidental deletion or a misconfigured lifecycle rule can remove it. Decide whether you need bucket replication, versioning or a separate backup account, and test a restore into a scratch bucket before you rely on it. Confirm the recovery point and recovery time your organization expects, because Prometheus local retention alone does not cover the history that Thanos keeps.

Questions teams ask before building long-term Thanos metrics

What does a long-term Thanos metrics build cost?

Thanos and Prometheus are open source under Apache-2.0, so there is no license fee for the software itself. The cost comes from four places: the infrastructure that runs Prometheus, Thanos components and query capacity; the object storage that holds months of blocks; the implementation work to design and deploy the stack; and the people who operate it after handover. Infrastructure and storage recur every month and grow with series count, scrape interval and retention. Implementation is one-time, and operations recur. Ask any quote to split these lines, state the retention period and cluster count it assumes, and name who owns the object storage bucket and its backups.

What drives how long a Thanos build takes?

Duration depends mostly on the number of clusters, whether each cluster already runs Prometheus with persistent disk, and whether the design needs sidecars, a receive path or both. Other drivers include the object storage platform you choose, network paths from each cluster to the central query layer, how many tenants or teams need isolated views, and how much of the existing alerting and dashboards must be validated during cutover. Thanos is built as a distributed system and is not recommended for production on a single node, so the test environment should mirror the production topology. Ask for a written scope with milestones before work starts, since DeployOpen engagements are typically fixed-scope and agreed in writing.

Can our own platform team build Thanos without a partner?

Yes, many teams do, and the software is open source with public documentation. The questions to answer honestly are whether your team has spare capacity for design, testing and a second round of operations, and whether it has experience with Prometheus storage behavior. Two details are easy to miss: Prometheus local compaction must be disabled when the sidecar uploads blocks, and the compactor must run as a singleton against each bucket. Your team should also plan for upgrades, since Thanos releases are frequent (v0.42.4 followed v0.42.0 within weeks in 2026). A partner can shorten the design phase, but internal ownership of the running system is still required.

What does our side need to provide before the build starts?

Plan for four inputs. First, an object storage target, such as one your organization already operates, with a bucket, credentials and a retention and backup policy agreed by the storage owner. Second, network paths from each cluster to the object storage endpoint and, where the query layer is central, from the query tier to each sidecar, store gateway or receive endpoint. Third, Prometheus access: service accounts or Prometheus Operator permissions to change the Prometheus configuration, persistent volumes, and the local block duration settings. Fourth, named owners for alerting, dashboards and sign-off on the query behavior that your users depend on. Confirm the exact requirements for your Prometheus version against the Thanos getting started guide.

Does Thanos replace Alertmanager or the Prometheus Operator?

No. Thanos does not replace Alertmanager. Prometheus still evaluates alert rules and sends alerts to Alertmanager, which handles grouping, inhibition and silences. Alertmanager can run as a cluster for high availability, and Prometheus should point at every Alertmanager instance rather than a load balancer. Thanos Rule can evaluate rules against the global view, which is a separate design decision and should be tested before you move any paging. The Prometheus Operator also remains useful for managing Prometheus instances in Kubernetes, and sidecars are commonly deployed alongside it. Confirm the chart and operator versions in your environment before changing how rules are loaded.

How does Thanos keep data for months without filling the disk?

Thanos stores historical blocks in object storage, so Prometheus can keep its default local retention while the long-term copy lives elsewhere. The Thanos compactor downsamples raw data older than 40 hours to 5-minute resolution, and 5-minute data older than 10 days to 1-hour resolution. These rules reduce query cost for long ranges but lower the detail available for old periods, so confirm which dashboards and alerts depend on full resolution. Prometheus local storage is not clustered or replicated, so the local volume still needs normal capacity planning and backups. Ask your team to test a long-range query before accepting the retention settings.

Which security and access controls should we review before go-live?

Review four areas. Object storage credentials should be scoped to the Thanos bucket and rotated through your normal secrets process. Query endpoints should sit behind your identity and network controls, since Prometheus does not provide built-in user authentication for its HTTP interfaces. Tenant separation matters if Thanos Receive serves several teams, because tenants are identified by the THANOS-TENANT header by default. Finally, the bucket needs an access log or audit trail that your compliance team can review. DeployOpen can test the setup and prepare the evidence your reviewers ask for, but audit reports and certifications come from independent auditors.

What should we ask for in a quote for this work?

Ask for a written scope that lists the topology (sidecar, receive or both), the number of clusters and Prometheus instances, the object storage target, the retention and downsampling settings, and the components to deploy, such as Query, Query Frontend, Store, Compact and Rule. Ask which deliverables are included: architecture and sizing notes, Helm or manifest configuration, runbooks, alert checks, a test plan and handover training. Ask what is excluded, such as dashboard rebuilds or upgrades after go-live, and whether ongoing support or upgrade work is available as a retainer. Compare quotes on those lines rather than on a headline number.

Building a multi-cluster view with Query federation

Thanos Query is the component that gives one PromQL endpoint across several Prometheus sources. It fans out each query to the endpoints it knows about, which can be Sidecars next to Prometheus (serving the Store API), Store gateways over object storage, and Receive instances that accept remote writes. Each endpoint returns the series it holds, and Query merges the results into a single answer. Before going live, decide which endpoints each Query instance will reach, and confirm that Query can reach them through the network paths and firewall rules of your clusters. Endpoint discovery is usually static or DNS-based in these setups, and a missing endpoint produces gaps that look like empty data rather than an error, so test each cluster with a known series before you trust the global view.

Every Prometheus source must carry unique external labels such as cluster and region, set through the external_labels block on each Prometheus or on the Receive tenant configuration. Query uses these labels to tell sources apart, and two clusters sharing identical external labels will silently merge their series. Deduplication is a separate step: Query collapses series that differ only by a replica label, which is how the two members of a Prometheus HA pair are merged into one stream. Choose the replica label name up front, keep it identical across the pair, and keep it distinct from the cluster label so that real cluster separation is never deduplicated away.

Query Frontend sits in front of Query and improves read paths by splitting long range queries into smaller intervals and caching results, which reduces repeated work on dashboards that refresh often. It does not change which data is returned, so it is an optimization to add after the federation is correct. Plan the access model at the same time: Query and Query Frontend usually receive no direct end-user traffic from every cluster, and the endpoints they call should be restricted to the Query service identity. Confirm these settings in your own environment, including how Grafana reaches Query Frontend, before you publish dashboards to teams.

How DeployOpen works on this

DeployOpen plans and implements Thanos inside your own infrastructure, starting from your existing Prometheus setup and object storage choice. The work is scoped in writing first, then built, tested, documented and handed to your team with the operating runbooks they need.

How we scope

  • Inventory existing Prometheus servers, HA pairs, clusters and retention requirements before choosing sidecar or receive.
  • Agree in writing which clusters, tenants, object storage buckets and query views are in scope.
  • Record which Thanos components will run, where, and which Prometheus settings must change.

How we build

  • Deploy Sidecar or Receive, Query, Store Gateway and Compactor in your cluster or data center.
  • Configure object storage access, bucket layout, and a single Compactor per bucket.
  • Test query results, deduplication of HA pairs, and downsampling behavior against agreed checks.

How we hand over

  • Provide written configuration, component diagrams and the retention and downsampling settings as built.
  • Document restore steps, compactor failure handling and how to add a new cluster to the query view.
  • Walk your platform and monitoring engineers through day-two operations before the engagement closes.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Upgrades to new Thanos releases are planned and tested against your configuration before rollout.
  • Confirm support terms, response expectations and upgrade cadence with us in the written scope.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.