Watch k8s events and trigger Handlers
VMware has made the difficult decision to stop driving this project and therefore we will no longer actively respond to issues or pull requests. The project will be externally maintained in the following fork: https://github.com/robusta-dev/kubewatch
Thank You.
[](https://goreportcard.com/report/github.com/bitnami-labs/kubewatch) [](https://godoc.org/github.com/bitnami-labs/kubewatch) [](https://github.com/bitnami-labs/kubewatch/blob/master/LICENSE)kubewatch is a Kubernetes watcher that currently publishes notification to available collaboration hubs/notification channels. Run it in your k8s cluster, and you will get event notifications through webhooks.
…When you have helm installed in your cluster, use the following setup:
helm install --name kubewatch bitnami/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:
rbac:
create: true
resourcesToWatch:
deployment: false
replicationcontroller: false
replicaset: false
daemonset: false
services: true
pod: true
job: false
node: false
clusterrole: true
serviceaccount: true
persistentvolume: false
namespace: false
secret: false
configmap: false
ingress: false
slack:
channel: '#YOUR_CHANNEL'
token: 'xoxb-YOUR_TOKEN'And use that:
$ helm upgrade --install kubewatch bitnami/kubewatch --values=values-file.ymlIn 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:
$ kubectl create -f kubewatch-configmap.yamlCreate the Pod directly, or create your own deployment:
$ kubectl create -f kubewatch.yamlA 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:
resource:
deployment: false
replicationcontroller: false
replicaset: false
daemonset: false
services: true
pod: true
job: false
node: false
clusterrole: false
serviceaccount: false
persistentvolume: false
namespace: false
secret: false
configmap: false
ingress: falseKubernetes Engine clusters running versions 1.6 or higher introduced Role-Based Access Control (RBAC). We can create ServiceAccount for it to work with RBAC.
$ kubectl create -f kubewatch-service-account.yamlIf 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_HEREEdit kubewatch.yaml, and create a new field under spec with serviceAccountName: kubewatch, you can achieve this by running:
$ sed -i '/spec:/a\ \ serviceAccountName: kubewatch' kubewatch.yamlThen just create pod as usual with:
$ kubectl create -f kubewatch.yaml…To Run Kubewatch Container interactively, place the config file in $HOME/.kubewatch.yaml location and use the following command.
docker run --rm -it --network host -v $HOME/.kubewatch.yaml:/root/.kubewatch.yaml -v $HOME/.kube/config:/opt/bitnami/kubewatch/.kube/config --name <container-name> bitnami/kubewatchExample:
…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 bitnami/kubewatchKubewatch 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.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
$ kubewatch config add slack --channel <slack_channel> --token <slack_token>You have an altenative choice to set your SLACK token, channel via environment variables:
$ export KW_SLACK_TOKEN='XXXXXXXXXXXXXXXX'
$ export KW_SLACK_CHANNEL='#channel_name'Create a flock bot.
Add flock webhook url to config using the following command.
$ kubewatch config add flock --url <flock_webhook_url>You have an altenative choice to set your FLOCK URL
$ export KW_FLOCK_URL='https://api.flock.com/hooks/sendMessage/XXXXXXXX'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$ kubewatch config test
Testing Handler configs from .kubewatch.yaml
2019/06/03 12:29:23 Message successfully sent to channel ABCD at 1559545162.000100To view the entire config file $HOME/.kubewatch.yaml use the following command.
$ kubewatch config view
Contents of .kubewatch.yaml
handler:
slack:
token: xoxb-xxxxx-yyyy-zzz
channel: kube-watch
hipchat:
token: ""
room: ""
url: ""
mattermost:
channel: ""
url: ""
username: ""
flock:
url: ""
webhook:
url: ""
resource:
deployment: false
replicationcontroller: false
replicaset: false
daemonset: false
services: false
pod: true
job: false
node: false
clusterrole: false
serviceaccount: false
persistentvolume: false
namespace: false
secret: false
configmap: false
ingress: false
namespace: ""
To manage the resources being watched, use the following command, changes will be saved to $HOME/.kubewatch.yaml.
……# 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 --svcClone the repository anywhere:
$ git clone https://github.com/bitnami-labs/kubewatch.git
$ cd kubewatch
$ go buildor
You can also use the Makefile directly:
$ make build$GOPATH$ make docker-image
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kubewatch latest 919896d3cd90 3 minutes ago 27.9MBRefer to the contribution guidelines to get started.
No open issues yet, or sync has not completed.