Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
/ k8s-notify Public archive

Turn kubernetes events into useful notifications & alerts

Notifications You must be signed in to change notification settings

redhat-cop/k8s-notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k8s-notify

k8s-notify is a 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? Create a feature request or contribute one yourself.

Examples

Check out the examples/ directory to see some sample use cases.

Quickstart

We’re going to walk through a sample use case.

Deploy k8s notify

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

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.

Configuring Notifications

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!

Trigger a Notification

Since our EventSubscription above triggers when a pod gets created, let’s create one.

kubectl run busybox --image=busybox

DING!

pod created

We got a message!

Contributing

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.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages