Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

kubewatch

> 编程语言
Open source

Watch k8s events and trigger Handlers

790 stars0 likes1 views
WebsiteGitHub

About

Watch k8s events and trigger Handlers

Fine-Grained Resource Tracking

KubeWatch tracks all changes to Kubernetes resources of given types.

If you need fine-grained filtering of which changes are forwarded, you can use KubeWatch in conjunction with Robusta.

For more details, refer to the Robusta docs on change-tracking.

A diagram showing the two options is shown below. The flow that only uses KubeWatch is purple and the flow that adds Robusta is green.

Latest image

robustadev/kubewatch:v2.9.0

Usage

…

Install

Cluster Installation

Using helm:

When you have helm installed in your cluster, use the following setup:

bash
helm repo add robusta https://robusta-charts.storage.googleapis.com && helm repo update
helm install kubewatch robusta/kubewatch --set='rbac.create=true,slack.channel=#YOUR_CHANNEL,slack.token=xoxb-YOUR_TOKEN,resourcesToWatch.pod=true,resourcesToWatch.daemonset=true'

You may also provide a values file instead:

…

And use that:

bash
$ helm upgrade --install kubewatch robusta/kubewatch --values=values-file.yml

Using kubectl:

In order to run kubewatch in a Kubernetes cluster quickly, the easiest way is for you to create a ConfigMap to hold kubewatch configuration.

An example is provided at kubewatch-configmap.yaml, do not forget to update your own slack channel and token parameters. Alternatively, you could use secrets.

Create k8s configmap:

bash
$ kubectl create -f kubewatch-configmap.yaml

Create the Pod directly, or create your own deployment:

bash
$ kubectl create -f kubewatch.yaml

A kubewatch container will be created along with kubectl sidecar container in order to reach the API server.

Once the Pod is running, you will start seeing Kubernetes events in your configured Slack channel. Here is a screenshot:

To modify what notifications you get, update the kubewatch ConfigMap and turn on and off (true/false) resources or configure any resource of your choosing with customresources (CRDs):

resource:
  deployment: false
  replicationcontroller: false
  replicaset: false
  daemonset: false
  services: true
  pod: true
  job: false
  node: false
  clusterrole: false
  clusterrolebinding: false
  serviceaccount: false
  persistentvolume: false
  namespace: false
  secret: false
  configmap: false
  ingress: false
  coreevent: false
  event: true
customresources:
  - group: monitoring.coreos.com
    version: v1
    resource: prometheusrules

Watching Secrets

Secret watching is off by default (secret: false). When you turn it on, kubewatch notifies on Secret creates, updates and deletes, but the secret material itself never leaves the process: the values under a Secret's data and stringData are replaced with [redacted by kubewatch] before any notification is built. This applies to the previous version of the object too, which update notifications also carry, and to Secrets reached through customresources rather than secret: true.

Key names, labels, annotations, the Secret's type and the rest of its metadata are kept, so a notification still tells you which Secret changed and which of its keys were added or removed — it just does not tell you their values. Handlers that serialize whole objects, such as cloudevent, redact again on the bytes they are about to send.

Working with RBAC

Kubernetes Engine clusters running versions 1.6 or higher introduced Role-Based Access Control (RBAC). We can create ServiceAccount for it to work with RBAC.

bash
$ kubectl create -f kubewatch-service-account.yaml

If you do not have permission to create it, you need to become an admin first. For example, in GKE you would run:

$ kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=REPLACE_EMAIL_HERE

Edit kubewatch.yaml, and create a new field under spec with serviceAccountName: kubewatch, you can achieve this by running:

bash
$ sed -i '/spec:/a\ \ serviceAccountName: kubewatch' kubewatch.yaml

Then just create pod as usual with:

bash
$ kubectl create -f kubewatch.yaml

Working with CRDs

kubewatch can be configured to monitor Kubernetes Custom Resource Definitions (CRDs), allowing you to receive notifications when changes occur. To configure kubewatch to watch custom resources, you need to define the customresources section either in your values file or by using the --set flag with Helm commands.

Include the custom resource configuration in your values file:

yaml
customresources:
  - group: monitoring.coreos.com
    version: v1
    resource: prometheusrules

Then deploy or upgrade kubwatch with helm upgrade or helm install

Alternatively, you can pass this configuration directly using the --set flag:

bash
helm install kubewatch robusta/kubewatch --set='rbac.create=true,slack.channel=#YOUR_CHANNEL,slack.token=xoxb-YOUR_TOKEN,resourcesToWatch.pod=true,resourcesToWatch.daemonset=true,customresources[0].group=monitoring.coreos.com,customresources[0].version=v1,customresources[0].resource=prometheusrules'

Custom RBAC roles

After defining custom resources, make sure that kubewatch has the necessary RBAC permissions to access the custom resources you've configured. Without the appropriate permissions, kubewatch will not be able to monitor your custom resources, and you won't receive notifications for changes.

To grant these permissions, you can define custom RBAC roles using customRoles within the rbac section of your values file or by using the --set flag with Helm commands. This allows you to specify exactly which API groups, resources, and actions kubewatch should have access to.

Here’s how you can configure the necessary permissions to monitor your resources:

yaml
rbac:
  create: true 
  customRoles:
    - apiGroups: ["monitoring.coreos.com"]
      resources: ["prometheusrules"]
      verbs: ["get", "list", "watch"]

Then deploy or upgrade kubwatch with helm upgrade or helm install

Alternatively, you can pass this configuration directly using the --set flag:

bash
helm install kubewatch robusta/kubewatch --set='rbac.create=true,slack.channel=#YOUR_CHANNEL,slack.token=xoxb-YOUR_TOKEN,customRoles[0].apiGroups={monitoring.coreos.com},customRoles[0].resources={prometheusrules},customRoles[0].verbs={get,list,watch}'

Metrics

kubewatch runs a Prometheus metrics endpoint at /metrics on port 2112 by default. This endpoint can be used to monitor health and the performance of kubewatch.

The kubewatch_events_total metric can help track the total number of Kubernetes events, categorized by resource type (e.g., Pods, Deployments) and event type (e.g., Create, Delete).

You can change the default port (2112) on which the metrics server listens by setting the LISTEN_ADDRESS environment variable. Format is host:port. :5454 means any host, and port 5454

yaml
extraEnvVars:
  - name: LISTEN_ADDRESS
    value: ":5454"

Local Installation

Using go package installer:

…

Using Docker:

To Run Kubewatch Container interactively, place the config file in $HOME/.kubewatch.yaml location and use the following command.

bash
docker run --rm -it --network host -v $HOME/.kubewatch.yaml:/root/.kubewatch.yaml -v $HOME/.kube/config:/opt/bitnami/kubewatch/.kube/config --name  robustadev/kubewatch

Example:

…

To Demonise Kubewatch container use

$ docker run --rm -d --network host -v $HOME/.kubewatch.yaml:/root/.kubewatch.yaml -v $HOME/.kube/config:/opt/bitnami/kubewatch/.kube/config --name kubewatch-app robustadev/kubewatch

Configure

Kubewatch supports config command for configuration. Config file will be saved at $HOME/.kubewatch.yaml

$ kubewatch config -h

config command allows admin setup his own configuration for running kubewatch

Usage:
  kubewatch config [flags]
  kubewatch config [command]

Available Commands:
  add         add webhook config to .kubewatch.yaml
  test        test handler config present in .kubewatch.yaml
  view        view .kubewatch.yaml

Flags:
  -h, --help   help for config

Use "kubewatch config [command] --help" for more information about a command.

Example:

slack:

  • Create a slack Bot

  • Edit the Bot to customize its name, icon and retrieve the API token (it starts with xoxb-).

  • Invite the Bot into your channel by typing: /invite @name_of_your_bot in the Slack message area.

  • Add Api token to kubewatch config using the following steps

    bash
    $ kubewatch config add slack --channel  --token 

    You have an altenative choice to set your SLACK token, channel via environment variables:

    bash
    $ export KW_SLACK_TOKEN='XXXXXXXXXXXXXXXX'
    $ export KW_SLACK_CHANNEL='#channel_name'

slackwebhookurl:

  • Create a slack app

  • Enable Incoming Webhooks. (On "Settings" page.)

  • Create an incoming webhook URL (Add New Webhook to Workspace on "Settings" page.)

  • Pick a channel that the app will post to, and then click to Authorize your app. You will get back your webhook URL.
    The Slack Webhook URL will look like: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

  • Add slack webhook url to kubewatch config using the following steps

    bash
    $ kubewatch config add slackwebhookurl --username  --emoji  --channel  --slackwebhookurl 

    Or, you have an altenative choice to set your SLACK channel, username, emoji and webhook URL via environment variables:

    bash
    $ export KW_SLACK_CHANNEL=slack_channel
    $ export KW_SLACK_USERNAME=slack_username
    $ export KW_SLACK_EMOJI=slack_emoji
    $ export KW_SLACK_WEBHOOK_URL=slack_webhook_url
  • Example apply done in a bash script:

bash
$ cat kubewatch-configmap-slackwebhook.yaml | sed "s||"\"$SlackChannel"\"|g;s||"\"$SlackUsesrName"\"|g;s||"\"$SlackEmoji"\"|g;s||"\"$WebhookUrl"\"|g" | kubectl create -f -
  • An example kubewatch-configmap-slackwebhook.yaml YAML File:
…

flock:

  • Create a flock bot.

  • Add flock webhook url to config using the following command.

    bash
    $ kubewatch config add flock --url 

    You have an altenative choice to set your FLOCK URL

    bash
    $ export KW_FLOCK_URL='https://api.flock.com/hooks/sendMessage/XXXXXXXX'

Testing Config

To test the handler config by send test messages use the following command.

$ kubewatch config test -h

Tests handler configs present in .kubewatch.yaml by sending test messages

Usage:
  kubewatch config test [flags]

Flags:
  -h, --help   help for test

Example:

$ kubewatch config test

Testing Handler configs from .kubewatch.yaml
2019/06/03 12:29:23 Message successfully sent to channel ABCD at 1559545162.000100

Viewing config

To view the entire config file $HOME/.kubewatch.yaml use the following command.

…

Resources

To manage the resources being watched, use the following command, changes will be saved to $HOME/.kubewatch.yaml.

…

Add/Remove resource:

…

Example:

bash
# rc, po and svc will be watched
$ kubewatch resource add --rc --po --svc

# rc, po and svc will be stopped from being watched
$ kubewatch resource remove --rc --po --svc

Changing log level

In case you want to change the default log level, add an environment variable named LOG_LEVEL with value from `trace/debug/info/warni

Issues· 30 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言