k8s-notify is a Kubernetes Operator that sends notifications to your favorite chat system.
A notifier is an integration with a chat system. Here are the ones we support right now.
-
Slack
-
Google Hangouts Chat
Don’t see the provider you’re looking for? Create a feature request or contribute one yourself.
Check out the examples/ directory to see some sample use cases.
We’re going to walk through a sample use case.
kubectl create namespace k8s-notify
kubectl apply -f deploy/service_account.yaml
kubectl apply -f deploy/role.yaml
kubectl apply -f deploy/role_binding.yaml
kubectl apply -f deploy/crds/event_v1_eventsubscription_crd.yaml
kubectl apply -f deploy/crds/notify_v1_notifier_crd.yaml
kubectl apply -f deploy/operator.yaml
k8s-notify allows you to describe a type of event and subscribe to receive notifications about it. To do this, k8s-notify provides a Custom Resource Definition called an EventSubscription
. A simple one looks like this:
apiVersion: event.redhat-cop.io/v1
kind: EventSubscription
metadata:
name: new-pod-subscription
spec:
matchMessage: 'Created pod'
notifier: slack-notify
Write this to a file called new-pod-subscription.yaml
and create it.
kubectl apply -f new-pod-subscription.yaml
This will trigger a notification any time a new pod is created in our namespace.
You may have noticed that the EventSubscription
we created contains a reference notifier: slack-notify
. In order to actually receive a notification, k8s-notify integrates with your chat provider of choice via a Custom Resource Definition called a Notifier
. This Notifier
can be referenced by name in an EventSubscription
. Let’s create the slack-notify
Notifier
to send messages via Slack.
First, we’ll need to create an Incoming Webhook. Copy the URL generated to feed into our config.
A Notifier
config looks like this. Make sure to paste in your webhook url.
apiVersion: notify.redhat-cop.io/v1
kind: Notifier
metadata:
name: slack-notify
spec:
slack:
webhook_url: https://hooks.slack.com/services/foo/bar/baz
Write that to a file called notifier-slack.yaml
and create it.
kubectl apply -f notifier-slack.yaml
Great, we’re all set up. Let’s take this sucker for a spin!
Run the following command to build the binary:
env GOOS=linux GOARCH=386 go build -o "build/_output/bin/k8s-notify" ./cmd/manager
docker build . -t <tag>
We welcome contributions from the community. Feel free to open issues and pull requests.
If you’re planning to contribute, check out our developer guide.