Lab 10.2: Installing and configuring AlertManager


AlertManager

AlertManager

AlertManager is an open-source alerting system that is designed to work seamlessly with the Prometheus Monitoring system.

Note: In this guide, all the Alert Manager Kubernetes objects will be created inside a namespace called monitoring. If you're using a different namespace, make sure to replace it in the YAML files accordingly.

AlertManager on Kubernetes Setup

Setting up AlertManager on Kubernetes involves the following key configurations:

  1. A ConfigMap for AlertManager configuration.
  2. A ConfigMap for AlertManager alert templates.
  3. AlertManager Kubernetes Deployment.
  4. AlertManager Service to access the web UI.

1. Create ConfigMap for AlertManager Configuration

Create a file named AlertManagerConfigmap.yaml using the command:

vim AlertManagerConfigmap.yaml

Inside the file, define the ConfigMap for AlertManager's configuration:

kind: ConfigMap
apiVersion: v1
metadata:
  name: alertmanager-config
  namespace: monitoring
data:
  config.yaml: |-
    global:
      route:
        receiver: alert-emailer
        group_by: ['alertname', 'priority']
        group_wait: 10s
        repeat_interval: 30m

    receivers:
    - name: alert-emailer
      email_configs:
      - to: "mail-example@gmail.com"
        from: "mail-example@gmail.com"
        smarthost: smtp.gmail.com:25
        auth_username: "mail-example@gmail.com"
        auth_identity: "mail-example@gmail.com"
        auth_password: "exampleauth"
        send_resolved: true

Note: To fill in the auth_password, generate an App password from here.

Create the ConfigMap using the command:

kubectl create -f AlertManagerConfigmap.yaml

2. Create ConfigMap for Alert Templates

Copy the template content from here, and create a file named AlertTemplateConfigMap.yaml:

vim AlertTemplateConfigMap.yaml

Apply the template using the command:

kubectl create -f AlertTemplateConfigMap.yaml

3. Create the Deployment

Create a file named Deployment.yaml:

vim Deployment.yaml

Inside the file, define the Deployment for AlertManager:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: alertmanager
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: alertmanager
  template:
    metadata:
      name: alertmanager
      labels:
        app: alertmanager
    spec:
      containers:
      - name: alertmanager
        image: prom/alertmanager:latest
        args:
          - "--config.file=/etc/alertmanager/config.yaml"
          - "--storage.path=/alertmanager"
        ports:
        - name: alertmanager
          containerPort: 9093
        resources:
          requests:
            cpu: 500m
            memory: 500M
          limits:
            cpu: 1
            memory: 1Gi
        volumeMounts:
        - name: config-volume
          mountPath: /etc/alertmanager
        - name: templates-volume
          mountPath: /etc/alertmanager-templates
        - name: alertmanager
          mountPath: /alertmanager
      volumes:
      - name: config-volume
        configMap:
          name: alertmanager-config
      - name: templates-volume
        configMap:
          name: alertmanager-templates
      - name: alertmanager
        emptyDir: {}

Create the Deployment using kubectl:

kubectl create -f Deployment.yaml

4. Create the AlertManager Service Endpoint

Create a file named Service.yaml:

vim Service.yaml

Inside the file, define the Service for the AlertManager:

apiVersion: v1
kind: Service
metadata:
  name: alertmanager
  namespace: monitoring
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/port:   '9093'
spec:
  selector: 
    app: alertmanager
  type: NodePort  
  ports:
    - port: 9093
      targetPort: 9093
      nodePort: 31000

Create the Service using the command:

kubectl create -f Service.yaml

5. Check the dployed alertmanager pod

kubectl get pods -n monitoring -o wide

image.png

6. Adjust the IP node and access the AlertManager Web UI

Access the AlertManager web UI using the following URL:

http://<your-node-IP>:31000

Replace <your-node-IP> with the actual IP address of your Kubernetes node. This will provide you access to the AlertManager interface for managing alerts.