Why Use Webhooks?
By default, the Flux Source Controller polls your Git repos at a specified interval (e.g., every 15 minutes):Notification Controller Overview
| Component | Purpose |
|---|---|
| Receiver | Listens on HTTP port 9292 inside the cluster for inbound webhook events. |
| Secret Validation | Verifies each incoming POST request using a shared HMAC token. |
| Event Handling | Forwards validated events to Flux controllers (e.g., Source Controller) to trigger an immediate pull. |
Step 1: Create a Git Source
First, define your Git repository as a FluxGitRepository source:
Step 2: Generate a Webhook Secret
Create a Kubernetes secret to secure your receiver endpoint:Keep your secret token safe—anyone with this token can trigger reconciliations.
Step 3: Expose the Notification Receiver
Expose the Notification Controller on port 80 (target port 9292). ChooseLoadBalancer or NodePort based on your cluster:
Step 4: Define the Receiver Resource
Create aReceiver resource to handle GitHub ping and push events for your GitRepository:
Step 5: Configure GitHub Webhook
- Open your GitHub repository settings and select Webhooks.
- Click Add webhook.
- Set Payload URL to the path shown by
flux get receivers(e.g.,https://<LB-IP>/hook/...). - Choose
application/jsonas the content type. - Enter the Secret:
secret-token-dont-share. - Select Let me select individual events, then check Push and Ping.
How It Works
- Push Event
GitHub sends a POST to the Flux receiver endpoint. - Validation
The Notification Controller computes an HMAC using the shared secret and compares it to theX-Hub-Signatureheader. - Reconciliation
Upon successful validation, the controller signals the Source Controller. Flux pulls the latest manifests immediately, regardless of the polling interval.
Ensure your webhook endpoint is secured by a network policy or firewall to prevent unauthorized access.
Next Steps
The Flux Notification Controller also supports alert providers and various event sources (e.g., DockerHub, SQS). Stay tuned for upcoming tutorials:- Configuring Alert Providers
- Consuming DockerHub Image Update Events
- Integrating with Cloud Event Brokers