1. Answers
  2. Deploying Alertmanager on Kubernetes

How do I deploy a Kubernetes monitoring.coreos.com alertmanager with Pulumi?

In this guide, we will deploy the Alertmanager component of Prometheus on a Kubernetes cluster using Pulumi. Alertmanager handles alerts sent by client applications such as the Prometheus server. It takes care of deduplicating, grouping, and routing them to the correct receiver integrations such as email, PagerDuty, or OpsGenie.

Steps

  1. Set up Pulumi and Kubernetes provider: Ensure you have Pulumi installed and configured, and you have access to a Kubernetes cluster.
  2. Define the Alertmanager deployment: We will create the necessary Kubernetes resources including a ConfigMap for configuration, a Deployment for running the Alertmanager pods, and a Service to expose the Alertmanager.

Below is the complete Pulumi program in TypeScript to deploy Alertmanager on a Kubernetes cluster:

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Define the Alertmanager configuration
const alertmanagerConfig = `
global:
  resolve_timeout: 5m
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 12h
  receiver: 'web.hook'
receivers:
- name: 'web.hook'
  webhook_configs:
  - url: 'http://example.com/'
`;

// Create a ConfigMap to store the Alertmanager configuration
const alertmanagerConfigMap = new k8s.core.v1.ConfigMap("alertmanager-config", {
    metadata: { name: "alertmanager-config" },
    data: { "alertmanager.yml": alertmanagerConfig },
});

// Create a Deployment for Alertmanager
const alertmanagerDeployment = new k8s.apps.v1.Deployment("alertmanager-deployment", {
    metadata: { name: "alertmanager" },
    spec: {
        selector: { matchLabels: { app: "alertmanager" } },
        replicas: 1,
        template: {
            metadata: { labels: { app: "alertmanager" } },
            spec: {
                containers: [{
                    name: "alertmanager",
                    image: "quay.io/prometheus/alertmanager:v0.21.0",
                    args: ["--config.file=/etc/alertmanager/config/alertmanager.yml"],
                    volumeMounts: [{
                        name: "config-volume",
                        mountPath: "/etc/alertmanager/config",
                    }],
                }],
                volumes: [{
                    name: "config-volume",
                    configMap: { name: "alertmanager-config" },
                }],
            },
        },
    },
});

// Create a Service to expose Alertmanager
const alertmanagerService = new k8s.core.v1.Service("alertmanager-service", {
    metadata: { name: "alertmanager" },
    spec: {
        selector: { app: "alertmanager" },
        ports: [{
            port: 9093,
            targetPort: 9093,
        }],
    },
});

export const alertmanagerUrl = alertmanagerService.status.loadBalancer.ingress[0].hostname;

Key Points

  • We defined the Alertmanager configuration in a ConfigMap.
  • We created a Deployment to run the Alertmanager container, mounting the configuration from the ConfigMap.
  • We exposed the Alertmanager using a Kubernetes Service.

Summary

In this guide, we deployed the Alertmanager component of Prometheus on a Kubernetes cluster using Pulumi. We created a ConfigMap to store the configuration, a Deployment to run the Alertmanager, and a Service to expose it. This setup ensures that Alertmanager is correctly configured and accessible within the Kubernetes cluster.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up