Six tools to Simplify Kubernetes Journey — Day 5 — Kubewatch — A watcher for Kubernetes

As per the official github link kubewatch is a Kubernetes watcher that publishes notifications to Slack/hipchat/mattermost/flock channels. It watches the cluster for resource changes and notifies them through webhooks.

Basically kubewatch looks for events like pod/deployment/confimap creation/deletion and sends notification to selected channels like

  • slack
  • hipchat
  • mattermost
  • flock
  • webhook
  • smtp

Installation

In this blog, we will use helm to install kubewatch and use slack as the notification medium. But before setting up helm and slack, you must need to have your running Kubernetes cluster. Please check the link on how to configure the Kubernetes cluster using kind.

Configuring Slack

  • Go to your slack workspace, and you have the option to create a new channel, or you can use an existing channel. For this demo, I am going to use an existing channel slacktest(but creating a new channel is pretty easy, you need to click on Create a new channel).
  • Once you have a slack channel, the next step is to get a slack token to integrate with Kubewatch. To create a slack token, go to https://api.slack.com/apps/new and create a new app. Give your App Name, for eg: kubewatch, and select your Development Slack Workspace for eg.100daysofdevops in this case.
  • In the next step we need to define our token scope. In this case we are using chat:write as scope which gives permission to post messages in approved channels & conversations.
  • Now scroll down and click on Oauth & Permissions and note Bot User OAuth Access token.
  • One more step you need to perform is to invite the Bot to the channel

/invite @BOT_NAME

/invite @kubewatch

Using helm

Once you have helm installed in your cluster(if you want more information about helm and install it, please follow this link).

  • Add the bitnami repo.
  • To verify it
  • Next, we will run a repo update to make sure all the charts are updated and in sync.
  • Search for kubewatch chart
  • As we know all helm chart comes with a default set of values but in this case, we want to modify these values according to our requirement.
  • Now open this file and modify few parameters. First, let start with slack and add the channel to send notification and add token we have created during the slack section.
  • In the next step, we need to define what I want to monitor. So, in this case, I want to monitor only the events from the default namespace(namespaceToWatch: “default”) and the resources to watch(deployment, services, pod). If you want to monitor any other resources, changes the parameter to true(for eg. replicaset: false to replicaset: true).
  • One important parameter you need to set is rbac to true. If you set it to a default value to false, then the service account this helm chart creates doesn’t have access to list Kubernetes resources such as pod, deployments, services, etc.
  • With all the configuration in place, its time to deploy the helm chart with our customized values.
  • If you now execute the command shown at the last command’s output, you will see the my-kubewatch pod created in the default namespace.

Testing

  • Try to create any pod in the default namespace
  • If you go to the slack channel, you will see a notification like this
  • You can also tail the logs of your pod to verify these notifications

Wrapping Up

Kubewatch is a powerful tool and sends a notification for any events happening in your Kubernetes cluster. But please configure it wisely, as too many notifications in the busy cluster might lead to notification fatigue, and you will start missing the important ones.