Aller au contenu principal

Notifications et Alertes


Table des matières

  1. Concept
  2. Providers
  3. Alerts
  4. Receivers (Webhooks)
  5. Exercices pratiques

1 - Concept

Notification Controller

Le Notification Controller gère :

  • Alerts : Envoyer des notifications sur des événements
  • Receivers : Recevoir des webhooks externes

CRDs disponibles

CRDDescription
ProviderDestination des notifications
AlertRègles de notification
ReceiverEndpoint pour webhooks entrants

🔝 Retour à la table des matières


2 - Providers

Slack

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: slack
namespace: flux-system
spec:
type: slack
channel: deployments
secretRef:
name: slack-webhook
---
apiVersion: v1
kind: Secret
metadata:
name: slack-webhook
namespace: flux-system
stringData:
address: https://hooks.slack.com/services/xxx/yyy/zzz

Microsoft Teams

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: teams
namespace: flux-system
spec:
type: msteams
secretRef:
name: teams-webhook
---
apiVersion: v1
kind: Secret
metadata:
name: teams-webhook
namespace: flux-system
stringData:
address: https://outlook.office.com/webhook/xxx

Discord

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: discord
namespace: flux-system
spec:
type: discord
secretRef:
name: discord-webhook

GitHub (commit status)

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: github-status
namespace: flux-system
spec:
type: github
address: https://github.com/my-org/my-repo
secretRef:
name: github-token
---
apiVersion: v1
kind: Secret
metadata:
name: github-token
namespace: flux-system
stringData:
token: ghp_xxxxxxxxxxxx

Tous les providers supportés

ProviderTypeDescription
SlackslackMessages Slack
TeamsmsteamsMessages Teams
DiscorddiscordMessages Discord
GitHubgithubCommit status
GitLabgitlabCommit status
BitbucketbitbucketCommit status
GenericgenericWebhook HTTP
PagerDutypagerdutyIncidents
OpsgenieopsgenieAlertes

🔝 Retour à la table des matières


3 - Alerts

Alert basique

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
name: on-call
namespace: flux-system
spec:
providerRef:
name: slack
eventSeverity: error
eventSources:
- kind: Kustomization
name: '*'
- kind: HelmRelease
name: '*'

Filtrer par namespace

spec:
eventSources:
- kind: Kustomization
name: '*'
namespace: production

Filtrer par sévérité

spec:
eventSeverity: info # info, error

Alert avec exclusions

spec:
eventSources:
- kind: Kustomization
name: '*'
exclusionList:
- ".*test.*"
- ".*dev.*"

Exemple complet

# Slack pour les erreurs production
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
name: production-errors
namespace: flux-system
spec:
summary: "Production deployment alert"
providerRef:
name: slack-production
eventSeverity: error
eventSources:
- kind: Kustomization
name: '*'
namespace: production
- kind: HelmRelease
name: '*'
namespace: production
---
# Slack pour tous les déploiements (info)
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
name: all-deployments
namespace: flux-system
spec:
summary: "Deployment notification"
providerRef:
name: slack-deployments
eventSeverity: info
eventSources:
- kind: Kustomization
name: '*'
- kind: HelmRelease
name: '*'

🔝 Retour à la table des matières


4 - Receivers (Webhooks)

Concept

Les Receivers permettent de déclencher une réconciliation Flux depuis l'extérieur.

Créer un Receiver

apiVersion: notification.toolkit.fluxcd.io/v1
kind: Receiver
metadata:
name: github-webhook
namespace: flux-system
spec:
type: github
events:
- ping
- push
secretRef:
name: webhook-token
resources:
- kind: GitRepository
name: my-repo

Secret pour le token

apiVersion: v1
kind: Secret
metadata:
name: webhook-token
namespace: flux-system
stringData:
token: <random-token>

Récupérer l'URL du webhook

# L'URL est générée automatiquement
kubectl get receiver github-webhook -n flux-system

# Format: /hook/<sha256-hash>

Configurer dans GitHub

  1. Aller dans Settings > Webhooks
  2. URL : https://flux.example.com/hook/<hash>
  3. Content-type : application/json
  4. Secret : le même token que dans le Secret

Types de receivers

TypeSource
githubGitHub webhooks
gitlabGitLab webhooks
bitbucketBitbucket webhooks
genericHTTP POST générique

🔝 Retour à la table des matières


5 - Exercices pratiques

Exercice 1 : Alertes Slack

# slack-notifications.yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: slack
namespace: flux-system
spec:
type: slack
channel: flux-alerts
secretRef:
name: slack-webhook
---
apiVersion: v1
kind: Secret
metadata:
name: slack-webhook
namespace: flux-system
stringData:
address: "YOUR_SLACK_WEBHOOK_URL"
---
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
name: all-events
namespace: flux-system
spec:
providerRef:
name: slack
eventSeverity: info
eventSources:
- kind: GitRepository
name: '*'
- kind: Kustomization
name: '*'

Exercice 2 : GitHub commit status

# github-status.yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
name: github
namespace: flux-system
spec:
type: github
address: https://github.com/MY-ORG/MY-REPO
secretRef:
name: github-token
---
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
name: github-status
namespace: flux-system
spec:
providerRef:
name: github
eventSeverity: info
eventSources:
- kind: Kustomization
name: my-app

Quiz

Q1. Quelle est la différence entre Alert et Receiver ?

Réponse
  • Alert : Envoie des notifications sortantes (Flux → Slack/Teams)
  • Receiver : Reçoit des webhooks entrants (GitHub → Flux)

Alert = notifier, Receiver = déclencher.

Q2. Comment filtrer les alertes pour n'avoir que les erreurs ?

Réponse
spec:
eventSeverity: error

Les valeurs possibles sont info (tout) et error (erreurs uniquement).

🔝 Retour à la table des matières


Points clés à retenir

  • Provider : destination (Slack, Teams, GitHub...)
  • Alert : règles de notification sortantes
  • Receiver : webhooks entrants pour trigger
  • Filtrer par sévérité et namespace
  • Webhooks pour sync instantané (pas d'attente polling)

← Chapitre précédent | Chapitre suivant : Multi-tenancy →