Featured image of post ArgoCD email notifications with Gmail

ArgoCD email notifications with Gmail

With ArgoCD managing CD pipeline for many of my applications, I really wanted a way to receive notifications about deployment changes, outages, etc.

ArgoCD Notifications seemed perfect for this, so I have set it up with my Gmail account, and here is how I did it.

Prerequisites

  1. A Kubernetes cluster with ArgoCD installed
  2. A Gmail account

Gmail account setup

Before installing the notification controller, generate a new app password for your gmail account, so that the notification controller can send emails on your behalf.

Feel free to set up a new Gmail account for this purpose. I just used my personal account to send notifications to myself.

See the “Create & use app passwords” section in Sign in with app passwords - Gmail Help for the steps, and keep the generated password around.

Installation

First, install the notification controller:

1
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/notifications_catalog/install.yaml

Then create a secret with the app password (email includes the “@gmail.com” part):

1
2
3
4
5
6
7
8
9
apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
  namespace: argocd
stringData:
  email-username: <email>
  email-password: <app-password>
type: Opaque

Check the logs of the notification controller to see if it picked up the config.

Configuration

In the argocd namespace, there should be a configmap called argocd-notifications-cm creaed along with the installation. Edit it and add the following to the data field:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  service.email: |
    username: $email-username
    password: $email-password
    host: smtp.gmail.com
    port: 465
    from: $email-username    
  subscriptions: |
    - recipients:
      - email: <your-email>
      triggers:
      - on-sync-failed
      - on-health-degraded
      - on-deployed
      - on-sync-status-unknown    

This will tell the notification controller to send emails to <your-email> when the specified triggers are fired.

A special case

Info

This section only applies if you manage multiple Kustomize applications under a single GitHub repository, and deploy them with ArgoCD.

As of the time of writing, the default triggers have a problem… The on-deployed trigger will fire for every application in the repository, not just the one that was deployed, resulting in an overwhelming amount of emails. overwhelmed

To fix this, you can modify the once-per field of the trigger.on-deployed section in argocd-notifications-cm. Example:

1
2
3
4
5
6
7
  trigger.on-deployed: |
    - description: Application is synced and healthy. Triggered once per commit.
      oncePer: app.status.operationState?.syncResult?.revision
      send:
      - app-deployed
      when: app.status.operationState != nil and app.status.operationState.phase in ['Succeeded']
        and app.status.health.status == 'Healthy'    

Testing

You can use either a new application or an existing one to test notifications. The easiest way is to just go to your ArgoCD UI and sync an application. You should see an email in your inbox shortly.

Conclusion

Using a Gmail account and an app password is not the most secure way, I know, but it is the easiest way to get notifications set up quickly.

Originally I was thinking about setting up a self-hosted mail server that I can use for other projects as well, but it was not as simple as I initially thought especially for outbound emails. Maybe I will figure it out one day.

Built with Hugo
Theme Stack designed by Jimmy