Skip to content

VMAlert alerting stack

Overview

This wiki documents the complete VMAlert alerting stack setup for the k3s-analytics production environment, replacing the old kube-prometheus alertmanager with VictoriaMetrics stack.


Architecture

VMAgent (scrape)
    ↓
VMSingle (store metrics)
    ↓                    ↘
VMAlert (evaluate rules)  Grafana (visualize)
    ↓
VMAlertmanager (route alerts)
    ↓
Gmail → <ALERTS_RECIPIENT_EMAIL>

Namespaces

Namespace Purpose
observability VM stack (VMSingle, VMAgent, VMAlert, VMAlertmanager)
monitoring Grafana, kube-state-metrics, node-exporter
production Production app alert rules
db PostgreSQL alert rules
zitadel Zitadel IAM alert rules

Components

Existing (before this setup)

Component Namespace Purpose
VMSingle observability Metrics storage
VMAgent observability Metrics scraping
VictoriaLogs observability Log storage
Grafana monitoring Visualization
kube-state-metrics monitoring K8s object metrics
node-exporter monitoring Node hardware metrics

Added (this setup)

Component Namespace Purpose
VMAlert observability Alert rule evaluation
VMAlertmanager observability Alert routing
VMAlertmanager-web svc observability Non-headless service for Grafana
VMRule CRDs production/db/zitadel/monitoring Alert rule definitions

Removed

Component Reason
kube-prometheus alertmanager Replaced by VMAlertmanager
kube-prometheus prometheus Not needed, using VMSingle
kube-prometheus prometheusOperator Not needed

File Structure

k3s-analytics/prod/04-vm-operator/
├── kustomization.yaml
├── vmalert.yaml
├── vmalertmanager.yaml
├── vmalertmanager-secret.yaml
└── alerts/
    ├── production/
    │   ├── pods.yaml          # PodCrashLooping, OOMKill, CPU, Memory
    │   ├── statefulset.yaml   # StatefulSet health
    │   ├── pvc.yaml           # PVC usage
    │   ├── hpa.yaml           # HPA scaling
    │   └── kustomization.yaml
    ├── db/
    │   ├── postgres.yaml      # PostgreSQL health
    │   └── kustomization.yaml
    ├── zitadel/
    │   ├── zitadel.yaml       # Zitadel health & error rate
    │   ├── hpa.yaml           # Zitadel HPA
    │   └── kustomization.yaml
    └── nodes/
        ├── nodes.yaml         # Node CPU, memory, disk, network
        └── kustomization.yaml

VMAlert Configuration

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMAlert
metadata:
  name: vmalert
  namespace: observability
spec:
  replicaCount: 1
  datasource:
    url: "http://vmsingle-victoria-metrics.observability.svc.cluster.local:8428"
  notifier:
    url: "http://vmalertmanager-vmalertmanager.observability.svc.cluster.local:9093"
  remoteWrite:
    url: "http://vmsingle-victoria-metrics.observability.svc.cluster.local:8428/api/v1/write"
  remoteRead:
    url: "http://vmsingle-victoria-metrics.observability.svc.cluster.local:8428"
  ruleNamespaceSelector:
    matchExpressions:
      - key: kubernetes.io/metadata.name
        operator: In
        values:
          - production
          - db
          - zitadel
          - monitoring
  ruleSelector: {}

Note: remoteWrite is only used for recording rules. Alert rules do not write back to VMSingle.


VMSingle — vmalert.proxyURL

To show VMAlert rules in Grafana's Alert rules page, VMSingle must proxy requests to VMAlert:

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMSingle
metadata:
  name: victoria-metrics
  namespace: observability
spec:
  extraArgs:
    vmalert.proxyURL: "http://vmalert-vmalert.observability.svc.cluster.local:8080"

VMAlertmanager Configuration

Email (Gmail SMTP)

global:
  smtp_smarthost: 'smtp.gmail.com:587'
  smtp_from: '<ALERTS_SENDER_GMAIL>'
  smtp_auth_username: '<ALERTS_SENDER_GMAIL>'
  smtp_auth_password: 'YOUR_GMAIL_APP_PASSWORD'
  smtp_require_tls: true
  smtp_hello: 'gmail.com'

route:
  group_by: ['alertname', 'namespace', 'severity']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  receiver: 'email-warning'
  routes:
    - match:
        severity: critical
      receiver: 'email-critical'
    - match:
        severity: warning
      receiver: 'email-warning'

receivers:
  - name: 'email-critical'
    email_configs:
      - to: '<ALERTS_RECIPIENT_EMAIL>'
        send_resolved: true
        headers:
          Subject: ' [CRITICAL] {{ .GroupLabels.alertname }} - {{ .GroupLabels.namespace }}'

  - name: 'email-warning'
    email_configs:
      - to: '<ALERTS_RECIPIENT_EMAIL>'
        send_resolved: true
        headers:
          Subject: ' [WARNING] {{ .GroupLabels.alertname }} - {{ .GroupLabels.namespace }}'

Note: Gmail App Password is required. Generate at Google Account → Security → 2-Step Verification → App Passwords.


Alert Rules Summary

production namespace

Alert Severity Condition
PodCrashLooping critical Pod restart rate > 0 for 5m
PodNotReady warning Pod not ready for 5m
PodOOMKilled critical Pod OOMKilled
DeploymentReplicasMismatch warning Desired != available replicas
PodHighCPU warning CPU > 90% for 10m
PodHighMemory warning Memory > 90% of limit for 10m
StatefulSetNotReady critical StatefulSet replicas not ready
PVCUsageHigh warning PVC > 85% full
PVCUsageCritical critical PVC > 95% full
PVCPending critical PVC stuck in Pending
HPAMaxedOut warning HPA at max replicas for 15m
HPAScalingStuck warning HPA current != desired for 15m

db namespace

Alert Severity Condition
PostgresDown critical Postgres unreachable for 2m
PostgresHighConnections warning Connections > 85% of max
PostgresDeadlocks warning Deadlocks detected
PostgresSlowQueries warning Query running > 5min
PostgresReplicationLag critical Replication lag > 60s
PostgresPodNotReady critical Postgres pod not ready

zitadel namespace

Alert Severity Condition
ZitadelDown critical Zitadel unreachable for 2m
ZitadelPodNotReady critical Pod not ready for 3m
ZitadelCrashLooping critical Pod crash looping
ZitadelHighErrorRate critical HTTP 5xx > 5% for 5m
ZitadelHighLatency warning p99 latency > 2s for 5m
ZitadelOOMKilled critical Pod OOMKilled
ZitadelHPAMaxedOut warning HPA at max replicas for 15m

monitoring namespace (nodes)

Alert Severity Condition
NodeNotReady critical Node not ready for 2m
NodeUnreachable critical Node unreachable for 2m
NodeHighCPU warning CPU > 85% for 10m
NodeCPUCritical critical CPU > 95% for 5m
NodeHighMemory warning Memory > 85% for 10m
NodeMemoryCritical critical Memory > 95% for 5m
NodeDiskSpaceLow warning Disk < 15% free
NodeDiskSpaceCritical critical Disk < 5% free
NodeDiskFilling warning Disk will fill in 24h
NodeNetworkErrors warning Network receive errors
NodeHighLoad warning Load avg > 2 per CPU
NodeDiskPressure critical Node has disk pressure
NodeMemoryPressure critical Node has memory pressure
NodePIDPressure critical Node has PID pressure

How Alerts Work

1. VMRule defines:    alert name, PromQL expr, for duration, severity label
        ↓
2. VMAlert queries:   VMSingle every 1 min with the expr
        ↓
3. Alert states:      INACTIVE → PENDING → FIRING
        ↓
4. On FIRING:         VMAlert sends to VMAlertmanager
        ↓
5. Alertmanager:      groups by [alertname, namespace, severity]
                      waits group_wait: 30s
                      routes by severity label
        ↓
6. Email sent:         critical → #alerts-critical
                       warning  → #alerts-warning
        ↓
7. On resolve:        send_resolved: true → resolved email sent

Node Alert — Label Join Explanation

Node exporter metrics use IP as instance label but kube_node_info uses node name. A join is required:

label_replace(
  (metric_expr) > threshold,
  "instance", "$1", "instance", "(.+):.+"   # strips :9100 port
)
* on(instance) group_left(node)
label_replace(
  kube_node_info,
  "instance", "$1", "internal_ip", "(.+)"   # copies internal_ip to instance
)

Result: alerts show ticket-node-1 instead of <TICKET_NODE_1_IP>:9100.


Grafana Integration

Datasources Required

Datasource Type URL Purpose
victoriametrics-metrics-datasource VictoriaMetrics http://vmsingle-victoria-metrics.observability.svc.cluster.local:8428 Metrics & dashboards
VictoriaMetrics-Rules Prometheus http://vmsingle-victoria-metrics.observability.svc.cluster.local:8428 Show VMAlert rules in Alert rules page
VMAlertmanager Alertmanager http://vmalertmanager-web.observability.svc.cluster.local:9093 Firing alerts & silences

Note: A plain Prometheus type datasource is required (not VictoriaMetrics type) to show rules in Grafana's Data source-managed section.

Additional Service Required

VMAlertmanager creates a headless service by default. A regular ClusterIP service is needed for Grafana:

apiVersion: v1
kind: Service
metadata:
  name: vmalertmanager-web
  namespace: observability
spec:
  selector:
    app.kubernetes.io/name: vmalertmanager
  ports:
    - port: 9093
      targetPort: 9093
      name: web
Dashboard Grafana ID
VictoriaMetrics 10229
VMAgent 12683
Node Exporter 1860
PostgreSQL 9628
Kubernetes pods 15760

Apply Order

# 1. Alertmanager secret first
kubectl apply -f vmalertmanager-secret.yaml

# 2. Alertmanager
kubectl apply -f vmalertmanager.yaml

# 3. VMAlert
kubectl apply -f vmalert.yaml

# 4. Rules per namespace
kubectl apply -k alerts/production/
kubectl apply -k alerts/db/
kubectl apply -k alerts/zitadel/
kubectl apply -k alerts/nodes/

# 5. Alertmanager web service
kubectl apply -f vmalertmanager-web-svc.yaml

Verification Commands

# Check all components running
kubectl get vmalert,vmalertmanager -n observability

# Check all VMRules operational
kubectl get vmrule -n production
kubectl get vmrule -n db
kubectl get vmrule -n zitadel
kubectl get vmrule -n monitoring

# Check VMAlert logs
kubectl logs -l app.kubernetes.io/name=vmalert -n observability --tail=50

# Check VMAlertmanager logs
kubectl logs -l app.kubernetes.io/name=vmalertmanager -n observability --tail=50

# Port forward VMAlert UI
kubectl port-forward svc/vmalert-vmalert 8080:8080 -n observability
# open http://localhost:8080

# Port forward Alertmanager UI
kubectl port-forward svc/vmalertmanager-web 9093:9093 -n observability
# open http://localhost:9093

# Test email alert
curl -X POST http://localhost:9093/api/v2/alerts \
  -H 'Content-Type: application/json' \
  -d '[{
    "labels": {
      "alertname": "TestAlert",
      "severity": "critical",
      "namespace": "production"
    },
    "annotations": {
      "summary": "This is a test alert"
    },
    "startsAt": "2026-07-01T03:38:00Z",
    "endsAt": "2026-07-01T05:00:00Z"
  }]'

kube-prometheus Stack Changes

Step 1 — Disable unused components

helm upgrade kube-prometheus prometheus-community/kube-prometheus-stack \
  --version 75.9.0 \
  -n monitoring \
  --reuse-values \
  --set alertmanager.enabled=false \
  --set prometheus.enabled=false \
  --set prometheusOperator.enabled=false \
  --set defaultRules.rules.kubeControllerManager=false \
  --set defaultRules.rules.kubeProxy=false \
  --set defaultRules.rules.kubeSchedulerAlerting=false \
  --set kubeControllerManager.enabled=false \
  --set kubeProxy.enabled=false \
  --set kubeScheduler.enabled=false

Step 2 — Disable k3s false positive alert rules

helm upgrade kube-prometheus prometheus-community/kube-prometheus-stack \
  --version 75.9.0 \
  -n monitoring \
  --reuse-values \
  --set defaultRules.disabled.KubeAPIDown=true \
  --set defaultRules.disabled.KubeletDown=true

Step 3 — Delete leftover VMRules manually

kubectl delete vmrule kube-prometheus-kube-prome-kubernetes-system-controller-manager -n monitoring
kubectl delete vmrule kube-prometheus-kube-prome-kubernetes-system-kube-proxy -n monitoring
kubectl delete vmrule kube-prometheus-kube-prome-kubernetes-system-scheduler -n monitoring
kubectl delete vmrule kube-prometheus-kube-prome-kube-scheduler.rules -n monitoring

Why disabled

Component Reason
alertmanager Replaced by VMAlertmanager
prometheus Replaced by VMSingle
prometheusOperator Not needed
kubeControllerManager Embedded in k3s, no separate process
kubeProxy k3s uses its own proxy
kubeScheduler Embedded in k3s
KubeAPIDown k3s embeds apiserver — false positive
KubeletDown kubelet scraping not configured — false positive

Troubleshooting

Rules not showing in Grafana

  1. Check vmalert.proxyURL is set in VMSingle extraArgs
  2. Use plain Prometheus datasource type (not VictoriaMetrics)
  3. Enable Manage alert rules in Alerting UI in datasource settings

Email not received

  1. Check alertmanager logs: kubectl logs -l app.kubernetes.io/name=vmalertmanager -n observability
  2. Verify SMTP config in secret
  3. Use v2 API for test: POST /api/v2/alerts
  4. Check endsAt is in the future

VMAlert not picking up rules

  1. Verify namespace labels: kubectl get namespace <name> --show-labels
  2. Check ruleNamespaceSelector includes the namespace
  3. Check VMRule status: kubectl get vmrule -n <namespace>

Node alerts showing IP instead of node name

  • Verify label_replace strips port from instance: (.+):.+
  • Check kube_node_info has internal_ip label matching node exporter instance IP

Receivers — Supported Notification Channels

Receiver Config key
Email (SMTP) email_configs
Slack slack_configs
PagerDuty pagerduty_configs
Telegram telegram_configs
Microsoft Teams msteams_configs
Discord discord_configs
OpsGenie opsgenie_configs
Webhook (any) webhook_configs

Last updated: 2026-07-01 Setup by: Chayanon