Setting Up Alert Manager on Kubernetes – Beginners Guide

Alert Manager on Kubernetes

AlertManager is an open-source alerting system that works with the Prometheus Monitoring system. This blog is part of the Prometheus Kubernetes tutorial series.

In our previous posts, we have looked at the following.

  1. Setup Prometheus on Kubernetes
  2. Setup Kube State Metrics

In this guide, I will cover the Alert Manager setup and its integration with Prometheus.

Note: In this guide, all the Alert Manager Kubernetes objects will be created inside a namespace called monitoring. If you use a different namespace, you can replace it in the YAML files.

Alertmanager on Kubernetes

Alert Manager setup has the following key configurations.

  1. A config map for AlertManager configuration
  2. A config Map for AlertManager alert templates
  3. Alert Manager Kubernetes Deployment
  4. Alert Manager service to access the web UI.

Important Setup Notes

You should have a working Prometheus setup up and running.

Prometheus should have the correct alert manager service endpoint in its config.yaml as shown below to send the alert to Alert Manager.

Note: If you are following my tutorial on Prometheus Setup On Kubernetes, you don’t have to add the following configuration because it is part of the Prometheus configmap.

      - scheme: http
        - targets:
          - "alertmanager.monitoring.svc:9093"

All the alerting rules have to be present on Prometheus config based on your needs. It should be created as part of the Prometheus config map with a file named prometheus.rules and added to the config.yaml in the following way.

      - /etc/prometheus/prometheus.rules

Alert manager alerts can be written based on the metrics you receive on Prometheus.

For receiving emails for alerts, you need to have a valid SMTP host in the alert manager config.yaml (smarthost parameter). You can customize the email template as per your needs in the Alert Template config map. We have given the generic template in this guide.

Let’s get started with the setup.

Alertmanager Kubernetes Manifests

All the Kubernetes manifests used in this tutorial can be found in this Github link.

Clone the Github repository using the following command.

git clone

Config Map for Alert Manager Configuration

Alert Manager reads its configuration from a config.yaml file. It contains the configuration of alert template path, email, and other alert receiving configurations.

In this setup, we are using email and slack webhook receivers. You can have a look at all the supported alert receivers from here.

Create a file named AlertManagerConfigmap.yaml and copy the following contents.

kind: ConfigMap
apiVersion: v1
  name: alertmanager-config
  namespace: monitoring
  config.yml: |-
    - '/etc/alertmanager/*.tmpl'
      receiver: alert-emailer
      group_by: ['alertname', 'priority']
      group_wait: 10s
      repeat_interval: 30m
        - receiver: slack_demo
        # Send severity=slack alerts to slack.
            severity: slack
          group_wait: 10s
          repeat_interval: 1m
    - name: alert-emailer
      - to: [email protected]
        send_resolved: false
        from: [email protected]
        require_tls: false
    - name: slack_demo
      - api_url:
        channel: '#devopscube-demo'

Let’s create the config map using kubectl.

kubectl create -f AlertManagerConfigmap.yaml

Config Map for Alert Template

We need alert templates for all the receivers we use (email, Slack, etc). Alert manager will dynamically substitute the values and deliver alerts to the receivers based on the template. You can customize these templates based on your needs.

Create a file named AlertTemplateConfigMap.yaml and copy the contents from this file link ==> Alert Manager Template YAML

Create the configmap using kubectl.

kubectl create -f AlertTemplateConfigMap.yaml

Create a Deployment

In this deployment, we will mount the two config maps we created.

Create a file called Deployment.yaml with the following contents.

apiVersion: apps/v1
kind: Deployment
  name: alertmanager
  namespace: monitoring
  replicas: 1
      app: alertmanager
      name: alertmanager
        app: alertmanager
      - name: alertmanager
        image: prom/alertmanager:latest
          - "--config.file=/etc/alertmanager/config.yml"
          - "--storage.path=/alertmanager"
        - name: alertmanager
          containerPort: 9093
              cpu: 500m
              memory: 500M
              cpu: 1
              memory: 1Gi
        - name: config-volume
          mountPath: /etc/alertmanager
        - name: templates-volume
          mountPath: /etc/alertmanager-templates
        - name: alertmanager
          mountPath: /alertmanager
      - name: config-volume
          name: alertmanager-config
      - name: templates-volume
          name: alertmanager-templates
      - name: alertmanager
        emptyDir: {}

Create the alert manager deployment using kubectl.

kubectl create -f Deployment.yaml

Create the Alert Manager Service Endpoint

We need to expose the alert manager using NodePort or Load Balancer just to access the Web UI. Prometheus will talk to the alert manager using the internal service endpoint.

Create a Service.yaml file with the following contents.

apiVersion: v1
kind: Service
  name: alertmanager
  namespace: monitoring
  annotations: 'true'   '9093'
    app: alertmanager
  type: NodePort  
    - port: 9093
      targetPort: 9093
      nodePort: 31000

Create the service using kubectl.

kubectl create -f Service.yaml

Now, you will be able to access Alert Manager on Node Port 31000. For example,
kubernetes alertmanager dasbboard
  1. Very nice tutorial. Can you tell how do we extend this to deploy alertmanager for high availability in kubernetes. How do we create multiple alertmanagers and connect them as peers?

  2. Is there a way to configure the prometheus endpoint to use in Alertmanager? All of the links Alertmanager shows link to the service endpoint which is not routable outside of the cluster.

  3. Hello, thank you for the clear tutorial. But my deployment is not running due to “Back-off restarting failed container” issue. How could i fix this?

    1. Hi Jerry,

      What does the pod event/logs say? do you have enough node CPU and memory to run the pods?

  4. Hi , I am facing the same issue , how to fix it . Have used the same yaml as shown in the link

      1.	DOWN	
        4m 46s ago	6.976ms	Get "": dial tcp connect: connection refused

        This is the error I am facing. Whereas the alert is reflected in my alert manager, but I am not getting emails in my inbox

        1. In Prometheus, it is showing down because of the wrong port in the Prometheus annotation in the Alert manager service manifest. I have corrected it in Github as well as the post.

          It was 8080,


          Now I changed to the correct port.


          Please re-apply for the service and the service status will be up.

          For email, please if check the SMTP configurations are correct. You need a valid SMTP host for sending emails from the alert manager.

  5. Hi
    Amazing tutorial, very well explained.
    I have one question to get nodes details and services? Do I need to deploy anything else? I have configured rule for kubelet service but have not received an alert in the mail while I can get your high memory demo mail. please let me know .

  6. Thank you for a very good blog, I have few challenges with the setup. I see that in the target section the alert manger seems to be down. how do I fix it.
    DOWN instance=”″ job=”kubernetes-service-endpoints” kubernetes_name=”alertmanager” kubernetes_namespace=”monitoring” 1.228s ago 873.8us Get “”: dial tcp connect: connection refused

  7. Nicely explained. Thank you for you descriptive blog.
    I have setup prometheus, grafana, kube-metrics and alertmanager.
    But in alertmanager I am not able to see alerts in alertmanager page.
    Could you guide me in that?

    1. Sure Deep. Are the alerts triggering? You can set up an alert with very less threshold and see if the alert is triggering

      1. I can see the alerts are triggering.
        Initially I have setup two alerts 1)instance showing status down 2) High Pod Memory (which is shown by your config also). Moreover, in prometheus webpage under target section, endpoint of alermanager is showing down.
        However, on alertmanager page I am not able to see the alerts for instance down and High Pod Memory.

          1. Now it’s working fine. I was using different namespace for my env.
            Thanks again for your support.

  8. nice tutorial! there’s one more question:
    how to verify Prometheus and Alertmanager are connected?

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like