k8s-notify
k8s-notify copied to clipboard
Turn kubernetes events into useful notifications & alerts
= k8s-notify :project_name: k8s-notify
{project_name} is a link:https://github.com/operator-framework/operator-sdk[Kubernetes Operator] that sends notifications to your favorite chat system.
== Supported Notifiers
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? link:https://github.com/etsauer/k8s-notify/issues/new[Create a feature request] or contribute one yourself.
== Examples
Check out the link:examples/[examples/] directory to see some sample use cases.
== Quickstart
We're going to walk through a sample use case.
=== Deploy k8s notify
[source,bash]
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
=== Subscribe to an Event
{project_name} allows you to describe a type of event and subscribe to receive notifications about it. To do this, {project_name} provides a Custom Resource Definition called an EventSubscription. A simple one looks like this:
[source,yaml]
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.
[source,bash]
kubectl apply -f new-pod-subscription.yaml
This will trigger a notification any time a new pod is created in our namespace.
=== Configuring Notifications
You may have noticed that the EventSubscription we created contains a reference notifier: slack-notify. In order to actually receive a notification, {project_name} 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 link:https://api.slack.com/incoming-webhooks#create_a_webhook[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.
[source,yaml]
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.
[source,bash]
kubectl apply -f notifier-slack.yaml
Great, we're all set up. Let's take this sucker for a spin!
=== Trigger a Notification
Since our EventSubscription above triggers when a pod gets created, let's create one.
[source,bash]
kubectl run busybox --image=busybox
DING!
image::/docs/images/pod-created.png[]
We got a message!
== Contributing
We welcome contributions from the community. Feel free to link:https://github.com/etsauer/k8s-notify/issues/new[open issues] and link:https://github.com/etsauer/k8s-notify/pulls/new[pull requests].
If you're planning to contribute, check out our link:/docs/dev_guide.adoc[developer guide].