alertmanager

by ScriptonBasestar

Helm chartv0.4.0App 0.29.0

Prometheus Alertmanager for alert routing and notification with high availability support

About this chart

Alertmanager Helm Chart

Prometheus Alertmanager for alert routing and notification with high availability support

Features

  • High Availability: Multi-replica support with automatic peer discovery
  • Alert Routing: Flexible routing tree with grouping and inhibition
  • Multiple Receivers: Email, Slack, PagerDuty, Webhook, and more
  • Silences: Temporary alert suppression with TTL
  • Template Support: Custom notification templates
  • API v2: RESTful API for alert and silence management
  • ServiceMonitor: Prometheus Operator integration
  • Operational Tools: 20+ Makefile commands

TL;DR

helm repo add scripton-charts https://scriptonbasestar-container.github.io/sb-helm-charts
helm repo update

# Install with default configuration (single replica)
helm install my-alertmanager scripton-charts/alertmanager

# Install with HA mode (3 replicas)
helm install my-alertmanager scripton-charts/alertmanager \
  --set replicaCount=3 \
  --set persistence.enabled=true

# Install with production configuration
helm install my-alertmanager scripton-charts/alertmanager \
  -f values-small-prod.yaml

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.0+
  • Prometheus for alert generation
  • (Optional) Prometheus Operator for ServiceMonitor

Configuration

Key Parameters

ParameterDescriptionDefault
replicaCountNumber of replicas (HA mode if > 1)1
alertmanager.retentionData retention period120h
config.global.resolveTimeoutTime to wait for resolve5m
config.route.groupByLabels to group alerts['alertname', 'cluster', 'service']
config.route.repeatIntervalInterval to resend notifications12h
persistence.enabledEnable persistent storagefalse
serviceMonitor.enabledEnable ServiceMonitorfalse

Operational Commands

Basic Operations

# View logs
make -f make/ops/alertmanager.mk am-logs

# View logs from all pods
make -f make/ops/alertmanager.mk am-logs-all

# Open shell
make -f make/ops/alertmanager.mk am-shell

# Restart
make -f make/ops/alertmanager.mk am-restart

Health & Status

# Check status
make -f make/ops/alertmanager.mk am-status

# Check version
make -f make/ops/alertmanager.mk am-version

# Check health
make -f make/ops/alertmanager.mk am-health

# Check cluster status (HA mode)
make -f make/ops/alertmanager.mk am-cluster-status

Configuration Management

# View configuration
make -f make/ops/alertmanager.mk am-config

# Reload configuration
make -f make/ops/alertmanager.mk am-reload

# Validate configuration
make -f make/ops/alertmanager.mk am-validate-config

Alerts Management

# List all alerts
make -f make/ops/alertmanager.mk am-list-alerts

# List alerts in JSON
make -f make/ops/alertmanager.mk am-list-alerts-json

# Get specific alert
make -f make/ops/alertmanager.mk am-get-alert FINGERPRINT=abc123

Silences Management

# List all silences
make -f make/ops/alertmanager.mk am-list-silences

# Get specific silence
make -f make/ops/alertmanager.mk am-get-silence ID=abc123

# Delete silence
make -f make/ops/alertmanager.mk am-delete-silence ID=abc123

Port Forward

# Port forward to localhost:9093
make -f make/ops/alertmanager.mk am-port-forward

# Then visit http://localhost:9093

High Availability Mode

Enable HA by setting replicaCount > 1:

replicaCount: 3

persistence:
  enabled: true
  size: 5Gi

podDisruptionBudget:
  enabled: true
  minAvailable: 2

How it works:

  • StatefulSet provides stable network identity
  • Headless service enables peer discovery
  • Gossip protocol (port 9094) synchronizes state
  • Each replica has independent storage
  • Cluster automatically handles leader election

Cluster Status:

make -f make/ops/alertmanager.mk am-cluster-status

Configuration Examples

Email Notifications

config:
  global:
    smtp:
      from: "[email protected]"
      smarthost: "smtp.gmail.com:587"
      authUsername: "[email protected]"
      authPassword: "your-app-password"
      requireTLS: true

  receivers:
    - name: email-team
      emailConfigs:
        - to: "[email protected]"
          headers:
            Subject: "[{{ .Status | toUpper }}] {{ .GroupLabels.alertname }}"

Slack Notifications

config:
  global:
    slackApiUrl: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"

  receivers:
    - name: slack-alerts
      slackConfigs:
        - channel: "#alerts"
          title: "{{ .GroupLabels.alertname }}"
          text: |-
            {{ range .Alerts }}
              *Alert:* {{ .Annotations.summary }}
              *Description:* {{ .Annotations.description }}
              *Severity:* {{ .Labels.severity }}
            {{ end }}

PagerDuty Integration

config:
  receivers:
    - name: pagerduty-critical
      pagerdutyConfigs:
        - serviceKey: "your-pagerduty-service-key"
          description: "{{ .GroupLabels.alertname }}"

Webhook Receiver

config:
  receivers:
    - name: webhook-receiver
      webhookConfigs:
        - url: "http://example.com/webhook"
          sendResolved: true
          httpConfig:
            basicAuth:
              username: "user"
              password: "pass"

Routing Examples

Route by Severity

config:
  route:
    receiver: default
    routes:
      - match:
          severity: critical
        receiver: pagerduty-critical
        continue: true
      - match:
          severity: warning
        receiver: slack-warnings

Route by Team

config:
  route:
    receiver: default
    routes:
      - match:
          team: frontend
        receiver: frontend-team
      - match:
          team: backend
        receiver: backend-team
      - match:
          team: devops
        receiver: devops-team

Inhibition Rules

Suppress warning alerts when critical alert is firing:

config:
  inhibitRules:
    - sourceMatch:
        severity: critical
      targetMatch:
        severity: warning
      equal: ['alertname', 'instance']

Integration with Prometheus

Prometheus Configuration

# prometheus.yml
alerting:
  alertmanagers:
    - kubernetes_sd_configs:
        - role: pod
      relabel_configs:
        - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_name]
          action: keep
          regex: alertmanager
        - source_labels: [__meta_kubernetes_pod_container_port_number]
          action: keep
          regex: "9093"

Using ServiceMonitor

serviceMonitor:
  enabled: true
  interval: 30s
  labels:
    prometheus: kube-prometheus

Alert Example

Example alert rule in Prometheus:

groups:
  - name: example
    rules:
      - alert: HighMemoryUsage
        expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10
        for: 5m
        labels:
          severity: warning
          team: devops
        annotations:
          summary: "High memory usage on {{ $labels.instance }}"
          description: "Memory usage is above 90% (current: {{ $value }}%)"

Production Setup

# values-prod.yaml
replicaCount: 3

alertmanager:
  retention: "120h"
  extraArgs:
    - --log.level=info
    - --cluster.reconnect-timeout=5m
    - --web.enable-lifecycle

config:
  global:
    resolveTimeout: "5m"
    smtp:
      from: "[email protected]"
      smarthost: "smtp.example.com:587"
      authUsername: "[email protected]"
      authPassword: "your-password"
      requireTLS: true

  route:
    groupBy: ['alertname', 'cluster', 'service']
    groupWait: 10s
    groupInterval: 10s
    repeatInterval: 12h
    receiver: default
    routes:
      - match:
          severity: critical
        receiver: pagerduty-critical
      - match:
          severity: warning
        receiver: slack-warnings

  inhibitRules:
    - sourceMatch:
        severity: critical
      targetMatch:
        severity: warning
      equal: ['alertname', 'cluster', 'service']

  receivers:
    - name: default
      emailConfigs:
        - to: "[email protected]"
    - name: pagerduty-critical
      pagerdutyConfigs:
        - serviceKey: "your-service-key"
    - name: slack-warnings
      slackConfigs:
        - channel: "#warnings"

serviceMonitor:
  enabled: true
  interval: 30s
  labels:
    prometheus: kube-prometheus

podDisruptionBudget:
  enabled: true
  minAvailable: 2

persistence:
  enabled: true
  size: 5Gi

resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 100m
    memory: 128Mi

affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                  - alertmanager
          topologyKey: kubernetes.io/hostname

priorityClassName: "system-cluster-critical"

Troubleshooting

Check Alertmanager Status

make -f make/ops/alertmanager.mk am-status

View Configuration

make -f make/ops/alertmanager.mk am-config

Check Cluster Health (HA mode)

make -f make/ops/alertmanager.mk am-cluster-status

Common Issues

Issue: Alerts not appearing in Alertmanager

Solution:

# Check Prometheus is sending alerts
kubectl logs -n monitoring prometheus-0 | grep alertmanager

# Check Alertmanager is receiving alerts
make -f make/ops/alertmanager.mk am-list-alerts

Issue: Notifications not being sent

Solution:

# Check receiver configuration
make -f make/ops/alertmanager.mk am-list-receivers

# Check logs for errors
make -f make/ops/alertmanager.mk am-logs

Issue: Cluster peers not connecting

Solution:

# Check cluster status
make -f make/ops/alertmanager.mk am-cluster-status

# Check headless service
kubectl get svc -n monitoring alertmanager-headless

# Check StatefulSet DNS
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup alertmanager-0.alertmanager-headless.monitoring.svc.cluster.local

API v2 Documentation

Alertmanager provides a RESTful API for alert and silence management:

Alerts API

# List alerts
curl http://localhost:9093/api/v2/alerts

# Get specific alert
curl http://localhost:9093/api/v2/alert/{fingerprint}

Silences API

# List silences
curl http://localhost:9093/api/v2/silences

# Create silence
curl -X POST -H "Content-Type: application/json" \
  -d '{
    "matchers": [{"name": "alertname", "value": "HighMemoryUsage", "isRegex": false}],
    "startsAt": "2024-01-01T00:00:00Z",
    "endsAt": "2024-01-01T12:00:00Z",
    "createdBy": "admin",
    "comment": "Maintenance window"
  }' \
  http://localhost:9093/api/v2/silences

# Delete silence
curl -X DELETE http://localhost:9093/api/v2/silence/{id}

Status API

# Get cluster status
curl http://localhost:9093/api/v2/status

Backup & Recovery

Backup Strategy

Alertmanager backup covers 4 components:

ComponentPrioritySizeBackup Method
ConfigurationCritical<10 KBConfigMap export
SilencesImportant<1 MBAPI export via amtool
Notification TemplatesImportant<100 KBConfigMap export
Data DirectorySecondary<100 MBPVC snapshot

Recovery Time Objective (RTO): < 30 minutes Recovery Point Objective (RPO): 1 hour

Quick Backup Commands

# 1. Backup Configuration (ConfigMap)
kubectl get configmap my-alertmanager-config -n default -o yaml > alertmanager-config-backup.yaml

# 2. Backup Silences (via amtool)
POD=$(kubectl get pods -n default -l app.kubernetes.io/name=alertmanager -o jsonpath='{.items[0].metadata.name}')
kubectl exec -n default $POD -- wget -qO- http://localhost:9093/api/v2/silences > silences-backup.json

# 3. Backup Notification Templates (if using ConfigMap)
kubectl get configmap my-alertmanager-templates -n default -o yaml > templates-backup.yaml

# 4. Backup Data Directory (PVC snapshot)
kubectl get pvc -n default my-alertmanager-0 -o yaml > pvc-backup.yaml
# Create VolumeSnapshot (requires CSI driver with snapshot support)
cat <<EOF | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: alertmanager-snapshot-$(date +%Y%m%d-%H%M%S)
  namespace: default
spec:
  volumeSnapshotClassName: csi-snapclass
  source:
    persistentVolumeClaimName: my-alertmanager-0
EOF

Backup Automation

Recommended: Hourly backups for silences, daily backups for configuration.

# CronJob for automated backups
apiVersion: batch/v1
kind: CronJob
metadata:
  name: alertmanager-backup
spec:
  schedule: "0 * * * *"  # Hourly
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: bitnami/kubectl:latest
            command:
            - /bin/sh
            - -c
            - |
              # Backup configuration
              kubectl get configmap my-alertmanager-config -n default -o yaml > /backup/config-$(date +%Y%m%d-%H%M%S).yaml

              # Backup silences via API
              POD=$(kubectl get pods -n default -l app.kubernetes.io/name=alertmanager -o jsonpath='{.items[0].metadata.name}')
              kubectl exec -n default $POD -- wget -qO- http://localhost:9093/api/v2/silences > /backup/silences-$(date +%Y%m%d-%H%M%S).json

              # 

Deploy alertmanager with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has alertmanager on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartalertmanager is pinned at v0.4.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply