Watch the recording here: https://youtu.be/cakxixc-yQk
❗️ Notifications & Alerts ⚠️
When operating a cluster, different teams may wish to receive notifications about the status of their GitOps pipelines. For example, the on-call team would receive alerts about reconciliation failures in the cluster, while the dev team may wish to be alerted when a new version of an app was deployed and if the deployment is healthy.
Webhook Receivers
The GitOps toolkit controllers are by design pull-based. In order to notify the controllers about changes in Git or Helm repositories, you can setup webhooks and trigger a cluster reconciliation every time a source changes. Using webhook receivers, you can build push-based GitOps pipelines that react to external events.
Alison Dowdney, Developer Experience Engineer at Weaveworks and CNCF Ambassador, walks through how to define a provider, an alert, git commit status, exposing the webhook receiver and defining a git repository and receiver.
Resources
Flux2 Documentation: https://fluxcd.io/docs/
Flux Guide: Setup Notifications: https://fluxcd.io/docs/guides/notifications/
Flux Guide: Setup Webhook receivers: https://fluxcd.io/docs/guides/webhook-receivers/
Flux Roadmap: https://fluxcd.io/docs/roadmap/
Alison's Demo Repo: https://github.com/alisondy/flux-demos
Boost Fertility New Invention Ups Success Rates.pdf
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
1. Setting up Notifications,
Alerts & Webhooks with Flux
Alison Dowdney, Developer Advocate, Weaveworks
Stacey Potter, Community Manager, Weaveworks
2. Weaveworks is founded on open source
● Flux (& GitOps Toolkit) (CNCF): GitOps for k8s
● Flagger (CNCF): Declarative Progressive Delivery for Service
Meshes
● Cortex (CNCF): Distributed, Long-term-storage TSDB
compatible with Prometheus
● Weave Ignite: VMs with container UX & built-in GitOps
management
● EKSctl: Create an Amazon EKS cluster with one command
● (and many many more projects!)
weave.works
3. Setting up Notifications, Alerts, & Webhooks w/ Flux
Speakers Help/Support
Duration
30-45 Minutes
Alison Dowdney
DX Engineer
Weaveworks
Stacey Potter
Community Mgr
Weaveworks
Browser
Safari copy/paste
shortcuts may not work
Using Zoom
Questions?
• Use chat (button: top
left corner of screen)
• Escape to exit full
screen
• “To Everyone” or “To
all panelists and
attendees”
Support:
https://support.zoom.us/hc/
en-us/articles/206175806-T
op-Questions
Troubleshooting
Use chat
If the issue is not easily resolved,
we ask that you follow along as
we demo the sample app.
4. 👋 Hello GitOps and Flux Users! 👋
Flux users! 😻 Sneak peek to the power
of Flux (v2)!
New users! ⚡ The Power of GitOps
with Flux!
5. 👋 Get Connected 💬 🤝
1. Fluxcd.io
2. Check out the Flux docs at:
https://toolkit.fluxcd.io/get-started/
3. GitHub Discussions Q&A:
https://github.com/fluxcd/flux2/discussi
ons/categories/q-a
4. CNCF Slack #Flux channel
6. ● GitOps is an app dev and operations methodology
● GitOps is a methodology, not a specific tool or
technology.
● GitOps applies to everything
and brings business value.
What is GitOps? … and why do I want it?
7. GitOps leverages:
● an entire system that is described declaratively
● code that is version controlled and
● software agents that reconcile and ensure correctness
(along with alerts, etc).
4 Principles of GitOps
9. Notifications, Alerts & Webhooks
*Note we’re not going to be covering them in this order! :)
The Plan
● Why you want notifications with Flux
● Setting up webhook received with Github
● Setting up Discord notifications with Flux
10. Why?
● When you're looking at the terminal only you know
what’s going on
● Surfacing alerts through messaging apps, and other services
gives your team visibility, and saves you time, as you don't
have to relay as many messages, flux is doing that for you
● Automation is one of the key principles of GitOps, less
manual ops === more time for building cool things
● and that’s why automation is one of the key business values
of gitops
● Read more at gitops.community
11. tl;dr Flux
● The most powerful tool to get the GitOps experience
● A set of Kubernetes controllers
● GitOps based continuous delivery system
12. Kubernet get
Create a kubernetes cluster using your tool of choice
I'm using k3ds eks because we're doing some loadbalancey stuff
and I don't really want to expose my dev station to the world
13. Bootstrap your cluster
1. Export tokens
2. Bootstrap
your cluster
3. Clone the cluster repository, then cd into it
$ export GITHUB_TOKEN=<your-token>
$ export GITHUB_USER=<your-username>
$ export REPO_NAME="woug-demo"
$ flux bootstrap github
--owner=$GITHUB_USER
--repository=$REPO_NAME
--branch=main
--personal
$ git clone git@github.com:$GITHUB_USER/$REPO_NAME
$ cd naw-example
16. Creating the receiver
create the receiver
$ flux create receiver flux-system
--type github
--event ping
--event push
--secret-ref webhook-token
--resource GitRepository/flux-system
--namespace flux-system
--export > naw-receiver.yaml
# naw-receiver.yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Receiver
metadata:
name: flux-system
namespace: flux-system
spec:
type: github
events:
- "ping"
- "push"
secretRef:
name: webhook-token
resources:
- kind: GitRepository
name: flux-system
It should produce the following:
Commit and push this all
17. Setup GitHub Webook
● Navigate to your repo's settings, and webhooks
● Create new webhook
● htto://url of loadbalancer , http insecure + path of hook flux
get receiver flux-system /hook
● $echo $TOKEN is the secret
18. Create a Discord Webhook
● assuming you have already created a discord server, if not
discord.new
● Create a text channel for your alerts
● Select the settings cog on the text channel you want to post
alerts into
● Select Create Webhook
● Give your Webhook a name, Copy the Webhook url, set aside
details for later
● Save changes
19. Define a provider
Create a secret with the webhook url
Create a notification provider for Discord by referencing the
above secret
$ kubectl -n flux-system create secret generic discord-url
--from-literal=address=https://discord.com/api/webhooks/YOUR_DISCORD/WEBHOOK
export $D_CHANNEL=""
export $D_BOTUSR=""
$ flux create alert-provider naw-provider
--type discord
--secret-ref discord-url
--channel $D_CHANNEL
--username $D_BOTUSR
--export > naw-provider.yaml
20. Define a provider (cont’d)
it should produce this file
# naw-provider.yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Receiver
metadata:
name: naw-provder
namespace: flux-system
spec:
channel: $D_CHANNEL
secretRef:
name: discord-url
type: discord
username: $D_BOTUSR
21. Define an alert
Create an alert definition for all repositories and Kustomizations
Yaml output
$ flux create alert naw-alert
--provider-ref naw-provider
--event-severity info
--event-source Kustomization/'*'
--event-source GitRepository/'*'
--namespace flux-system
--export > naw-alert.yaml
# naw-provider.yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Receiver
metadata:
name: naw-provder
namespace: flux-system
spec:
channel: $D_CHANNEL
secretRef:
name: discord-url
type: discord
username: $D_BOTUSR
22. Deploying the alert definitions to our
cluster
Commit the files to the repository
$ git add naw-alert.yaml
$ git add naw-provider.yaml
$ git commit -sm "Add alert, alert provider for
discord"
$ git push
23. Checking everything's in order
Use kubectl to get the status of the alert
$ kubectl -n flux-system get alerts
NAME READY STATUS AGE
naw-alert True Initialized 1m
24. Testing it out
Creating a new deployment
● Create a GitRepository source for podinfo
● Create a Kustomization for podinfo
$ flux create source git podinfo
--url=https://github.com/stefanprodan/podinfo
--branch=master
--interval=30s
--export > ./podinfo-source.yaml
$ flux create kustomization podinfo
--source=podinfo
--path="./kustomize"
--prune=true
--validation=client
--interval=5m
--export > ./podinfo-kustomization.yaml
25. Testing it out
● Commit them to git
$ git add podinfo-source.yaml
$ git add podinfo-kustomization.yaml
$ git commit -m "Add podinfo deployment"
$ git push
26. Testing it out: Creating some failures
● Create a invalid GitRepository source
● Delete source
$ flux create source git nonexist
--url=https://github.com/alisondy/nonexist
--branch=main
--interval=30s
--export > ./nonexist-source.yaml
$ git add nonexist-source.yaml
$ git commit -m "Add a faulty source"
$ git push
$ git rm nonexist-source.yaml
$ git commit -m "Get rid of the non existent source"
$ git push
27. What we did
● We setup a webhook receiver using flux
● Configured gitup to send push notifications to it
● We setup flux so it alerted in discord
With those skills you will be able to adopt one of the key gitops
principles we covered earlier...AUTOMATION!
28. Resources
- Flux Docs (https://fluxcd.io/docs/)
- Setup Notifications (https://fluxcd.io/docs/guides/notifications/)
- Setup Webhook Receivers
(https://fluxcd.io/docs/guides/webhook-receivers/)
- Alison’s Demo Repo (https://github.com/alisondy/flux-demos)
Alison’s slides.md
- YouTube Playlist: The Power of GitOps with Flux v2
(https://youtube.com/playlist?list=PL9lTuCFNLaD3fI_g-NXWVxopnJ0adn65d)
29. Migrate to Flux v2!
Sign up for our Flux Migration
Workshops!
bit.ly/FluxMigrationSurvey
30. Upcoming Events
April 28: CNCF Cloud Native Live: Migrating
from Flux v1 to Flux v2 (Leigh Capili)
April 29: Doing GitOps for multicloud resource management
using Crossplane and Flux2 (Leonardo Murillo @ Conf42: Cloud
Native 2021)
May 3: GitOpsCon @ KubeCon EU
June 9-10: GitOps Days 2021
GitOpsDays.com
31. Next Steps
• Join us on Flux discussions if you have more questions:
https://github.com/fluxcd/flux2/discussions
• Flux Community: https://fluxcd.io/community/
• Join the GitOps Community Group:
https://www.meetup.com/GitOps-Community/
• More info on GitOps? Visit www.gitops.community/
• Join the GitOps Community LinkedIn Group:
https://www.linkedin.com/groups/13914610/