Use Prometheus operator with DB volume for k8s
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
By default, the Prometheus Operator deploys Prometheus with emptyDir storage, meaning all metrics data is lost when the pod restarts. To persist data across pod restarts and upgrades, you must configure a persistent volume (PV) through the storage spec in the Prometheus custom resource or through Helm values. This ensures Prometheus retains its time-series database (TSDB) on a durable disk, which is critical for production monitoring where you need historical data.
The Problem: Data Loss on Restart
Configuring Storage via Helm Values
kube-prometheus-stack (Most Common)
Verify the PVC
Configuring Storage via Custom Resource
If you manage the Prometheus Operator directly (not via Helm):
Storage Classes by Cloud Provider
Sizing the Volume
Prometheus TSDB storage requirements depend on:
- Ingestion rate: Number of time series × scrape interval
- Retention period: How long you keep data
- Bytes per sample: ~1-2 bytes per sample after compression
Expanding an Existing Volume
If you run out of space, expand the PVC (requires the storage class to support volume expansion):
Or update the Helm values and upgrade:
Prometheus WAL and Compaction
High Availability with Persistent Storage
Each replica gets its own PVC. With ReadWriteOnce, each volume is attached to one pod. Both replicas scrape the same targets independently, providing redundancy.
Thanos/Cortex for Long-Term Storage
For retention beyond what local disk can hold, use Thanos or Cortex to ship data to object storage:
Common Pitfalls
- Forgetting
storageSpecentirely: WithoutstorageSpec, the Prometheus Operator usesemptyDir. Every pod restart, rollout, or node drain deletes all metrics. Always configure persistent storage for production. - Storage class does not support
ReadWriteOnce: Prometheus requiresReadWriteOnceaccess mode. Some NFS-based storage classes only supportReadWriteMany. Verify your storage class supportsRWObefore deploying. - Volume too small for retention period: If the volume fills up, Prometheus stops ingesting new data and may crash-loop. Monitor disk usage with
prometheus_tsdb_storage_limit_bytesand setretentionSizeas a safety cap. - Not enabling WAL compression: WAL files can consume significant disk space during high ingestion rates. Enable
walCompression: trueto reduce WAL size by approximately 50%. - PVC not deleted on Helm uninstall: Helm does not delete PVCs when uninstalling a release (by design, to prevent data loss). Manually delete PVCs with
kubectl delete pvc -l app.kubernetes.io/name=prometheus -n monitoringwhen you intentionally want to remove data.
Summary
- Configure
storageSpec.volumeClaimTemplatein the Prometheus Operator to use persistent volumes - Size the volume based on ingestion rate, retention period, and a 20% overhead margin
- Enable
walCompression: trueto reduce disk usage - Set both
retention(time) andretentionSize(bytes) to prevent disk exhaustion - Each Prometheus replica gets its own PVC with
ReadWriteOnceaccess mode - For long-term storage beyond local disk, use Thanos or Cortex with object storage (S3, GCS)
Related reading
- Use relative paths in Kubernetes config
- Use sub directory with kubernetes gitRepo volume mounts
- Using --sort-by with kubectl get pods --all-namespaces to sort by both namespace AND name doesn't work
- Using a connector with Helm-installed Kafka/Confluent
- uses for mongodb ObjectId creation time
- Using a .php file to generate a MySQL dump
- Use terraform to set up a lambda function triggered by a scheduled event source
- Using aws cli, what is best way to determine the current region

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.