Deploying VictoriaMetrics on Kubernetes: High-Performance Prometheus Alternative for Large-Scale Monitoring

DevOps tutorial - IT technology blog
DevOps tutorial - IT technology blog

The Real-World Problem: When Prometheus Hits the Scaling Wall

Prometheus works brilliantly out of the box. But as a cluster scales to 250 nodes and over 4,000 ephemeral pods, the cracks widen fast. You might find pods abruptly terminating with OOMKilled status during heavy user traffic, or whenever rolling deployments kick off high pod churn.

Our microservices fleet generates roughly 1.8 million metrics per minute across 12 million active series. Under peak load, engineer dashboards in Grafana began throwing 504 Gateway Timeouts. Prometheus demanded 64GB of RAM just to hold the TSDB head chunks in memory.

Simultaneously, our AWS EBS bill for gp3 PersistentVolumes climbed past $1,200 each month. Bumping CPU and memory limits brought only temporary breathing room. Within two weeks, a sudden metric spike took Prometheus down, blinding our on-call team in the middle of a P1 incident.

Root Cause Analysis: Why Standard Prometheus Struggles at Scale

The bottleneck lies in how the vanilla Prometheus TSDB manages index state and high-cardinality label sets. It retains active series for the last two hours in a write-ahead log (WAL) and memory-mapped chunks. Every unique label-value combination instantiates a distinct series.

When batch jobs terminate rapidly, or developers accidentally inject dynamic values like UUIDs or client IPs into metric labels, the inverted index explodes. Prometheus must keep all those stale series in memory.

Four primary architectural limits cause these failures:

  • Strict Vertical Scaling: Vanilla Prometheus is a single-binary architecture. You cannot partition ingestion load across identical replicas without running complex manual sharding or duplicate scrapers.
  • Compaction Memory Spikes: Every two hours, background routines merge 2-hour TSDB blocks into larger chunks. When series churn heavily inside that window, RAM consumption surges unpredictably and triggers the Linux OOM killer.
  • Disk Footprint: While Prometheus compresses data reasonably well at roughly 1.5 to 2 bytes per sample, disk usage still stacks up quickly, requiring expensive high-IOPS storage.
  • Long-Term Retention Overhead: Storing metrics beyond 15 to 30 days requires remote-write adapters. These add serialization penalties, network overhead, and another failure domain to manage.

Solutions Compared: Thanos vs. Cortex vs. VictoriaMetrics

Engineering teams that outgrow single-node Prometheus typically evaluate three architecture paths:

Feature / Metric Thanos Cortex / Mimir VictoriaMetrics
Architectural Footprint Moderate (Sidecars, Querier, Store Gateway, Compactor) Complex (Multi-tier microservices needing Consul/etcd, Ingesters, Distributors) Lean (Single binary or a straightforward 3-tier cluster)
RAM Consumption Moderate (constrained by Prometheus pod memory) Heavy (relies on caching layers like Memcached) Minimal (typically 4x to 7x less RAM than Prometheus)
Disk Compression Standard Prometheus blocks uploaded to object storage Block-based chunking in S3/GCS Outstanding (~0.4–0.7 bytes per sample, up to 10x savings)
Query Dialect PromQL PromQL MetricsQL (Full PromQL compatibility plus subquery extensions)

Thanos is practical if you want to leave existing Prometheus scrapers untouched and ship blocks off to Amazon S3 or GCS. Even so, it leaves the high-RAM ingestion bottleneck unresolved. Cortex and Grafana Mimir offer rock-solid multi-tenancy, yet operating their distributed topology demands dedicated platform engineers just to keep the coordination plane healthy.

VictoriaMetrics solves the core problem directly. It accepts standard PromQL and Prometheus remote-write payloads, slashes memory and CPU usage, compresses data aggressively, and scales horizontally without external state stores like ZooKeeper or etcd.

Deploying a VictoriaMetrics Cluster on Kubernetes

In large environments, the clustered architecture cleanly isolates data persistence (vmstorage), ingestion (vminsert), and query handling (vmselect). Metrics scraping shifts to vmagent, a lean daemon that handles scrape configs with a fraction of Prometheus’s memory footprint.

Separating these layers means ingestion spikes never stall active dashboard queries, and query-heavy incidents cannot trigger ingestion drops.

Step 1: Add the VictoriaMetrics Helm Repository

helm repo add vm https://victoriametrics.github.io/helm-charts/
helm repo update

Step 2: Configure the Cluster Topology

Draft a tailored values.yaml to specify data retention, persistence limits, and component replicas:

# vmcluster-values.yaml
vmstorage:
  replicaCount: 2
  retentionPeriod: "30d"
  storageDataPath: "/vm-data"
  persistence:
    enabled: true
    storageClassName: "gp3-csi"
    size: 100Gi
  resources:
    limits:
      cpu: "2"
      memory: "4Gi"
    requests:
      cpu: "500m"
      memory: "1Gi"

vminsert:
  replicaCount: 2
  resources:
    limits:
      cpu: "1"
      memory: "2Gi"
    requests:
      cpu: "250m"
      memory: "512Mi"

vmselect:
  replicaCount: 2
  cacheMountPath: "/cache"
  resources:
    limits:
      cpu: "2"
      memory: "4Gi"
    requests:
      cpu: "500m"
      memory: "1Gi"

Step 3: Deploy the Storage and Query Plane

kubectl create namespace monitoring
helm install vmcluster vm/victoria-metrics-cluster \
  --namespace monitoring \
  -f vmcluster-values.yaml

Step 4: Deploy vmagent for Metrics Scraping

vmagent handles scrape jobs using familiar Prometheus syntax. It buffers writes to local disk if network connectivity drops, ensuring zero data loss during upstream maintenance.

# vmagent-values.yaml
remoteWrite:
  - url: "http://vminsert-vmcluster.monitoring.svc.cluster.local:8480/insert/0/prometheus/api/v1/write"

config:
  scrape_configs:
    - job_name: "kubernetes-nodes-cadvisor"
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      kubernetes_sd_configs:
        - role: node
      relabel_configs:
        - action: labelmap
          regex: __meta_kubernetes_node_label_(.+)
        - target_label: __address__
          replacement: kubernetes.default.svc:443
        - source_labels: [__meta_kubernetes_node_name]
          regex: (.+)
          target_label: __metrics_path__
          replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor

Deploy the agent into the monitoring namespace:

helm install vmagent vm/victoria-metrics-agent \
  --namespace monitoring \
  -f vmagent-values.yaml

Step 5: Connect Grafana

Because VictoriaMetrics implements the Prometheus HTTP API, you do not need dedicated plugins. Add a standard Prometheus data source pointing straight at vmselect:

  • Name: VictoriaMetrics
  • Type: Prometheus
  • URL: http://vmselect-vmcluster.monitoring.svc.cluster.local:8481/select/0/prometheus/
  • Scrape interval: 15s

Verifying Ingestion and Query Execution

Forward port 8481 locally to test the query pipeline:

kubectl port-forward svc/vmselect-vmcluster 8481:8481 -n monitoring

Send a standard PromQL query to ensure metrics are resolving:

curl -G 'http://localhost:8481/select/0/prometheus/api/v1/query' \
  --data-urlencode 'query=sum(rate(container_cpu_usage_seconds_total[5m])) by (namespace)'

A successful JSON response containing cluster metrics confirms that vmagent, vminsert, and vmselect are communicating properly.

Switching to this architecture dropped our monitoring RAM usage from 64GB down to 10GB total across all components. Disk footprint fell by nearly 70%, and query latency stabilized below 120ms even during major deployments. Your monitoring stack should absorb production shocks, not cause them.

Share: