Notifications et Alertes
Table des matières
1 - Concept
Notification Controller
Le Notification Controller gère :
- Alerts : Envoyer des notifications sur des événements
- Receivers : Recevoir des webhooks externes
CRDs disponibles
| CRD | Description |
|---|---|
| Provider | Destination des notifications |
| Alert | Règles de notification |
| Receiver | Endpoint 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
| Provider | Type | Description |
|---|---|---|
| Slack | slack | Messages Slack |
| Teams | msteams | Messages Teams |
| Discord | discord | Messages Discord |
| GitHub | github | Commit status |
| GitLab | gitlab | Commit status |
| Bitbucket | bitbucket | Commit status |
| Generic | generic | Webhook HTTP |
| PagerDuty | pagerduty | Incidents |
| Opsgenie | opsgenie | Alertes |
🔝 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
- Aller dans Settings > Webhooks
- URL :
https://flux.example.com/hook/<hash> - Content-type :
application/json - Secret : le même token que dans le Secret
Types de receivers
| Type | Source |
|---|---|
github | GitHub webhooks |
gitlab | GitLab webhooks |
bitbucket | Bitbucket webhooks |
generic | HTTP 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)