Feedback

Chat Icon

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

GitOps: Example of a GitOps workflow using Argo CD
87%

Argo CD: Deployment Hooks

Hooks can be defined to execute before or after the application's deployment. For instance, a script can be run to send a notification to a Slack channel or an email to your team.

To define a hook, a Job should be created.

ℹ️ A Job is a Kubernetes-native resource that creates one or more Pods to perform a specific task that runs to completion, then terminates.

Here is a Job that sends an email after the application has been successfully deployed. It uses the argocd.argoproj.io/hook: PostSync annotation to specify that it should run after the synchronization of the application. The argocd.argoproj.io/hook-delete-policy: HookSucceeded annotation is used to delete the Job after it has successfully completed.

kubectl create -f - <
# Define a secret to store the SMTP password
---
apiVersion: v1
kind: Secret
metadata:
  name: smtp-password
  namespace: argocd
type: Opaque
stringData:
  password: 
# Define the Job to send an email
---
apiVersion: batch/v1
kind: Job
metadata:
  generateName: email-
  namespace: argocd
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
  template:
    spec:
      containers:
      - name: email
        image: bytemark/smtp
        command: ["/bin/sh"]
        args:
        - "-c"
        - "echo 'Hello World!' | mail -s 'Hello World!' "
        env:
        - name: RELAY_HOST
          value: 
        - name: RELAY_PORT
          value: 
        - name: RELAY_USERNAME
          value: 
        - name: RELAY_PASSWORD
          valueFrom:

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

Enroll now to unlock all content and receive all future updates for free.