Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 12, 2022 12:43 am GMT

Notify kubernetes events with botkube

At Cisco we use Webex as our IM collaboration engine. It is same as Teams/Slack with communication capabilities. One can build a bot for interaction and use APIs to communicate with webex teams.
As a platform team we want to notify interested parties when events happen like pod creation, deployment rollout, pod errors ...
When exploring around I came across botkube which can help solve our problem to a major extent

Architecture

Image description
Source: https://www.botkube.io/architecture/

Modes of usage
  • Full fledged chatbot - integrations to Slack, Mattermost and MS Teams
  • Sink - to push events, used for datastores like Elasticsearch and webhooks for use-cases
  • Custom filters - for validations and recommendations
Install botkube
  1. Prepare a webhook listener (<WEBHOOK_URL>)
  2. Decide on a name for your cluster (any string: <CLUSTER_NAME>)
  3. Get and update configuration values
$ wget https://raw.githubusercontent.com/infracloudio/botkube/v0.12.4/helm/botkube/sample-res-config.yaml$ mv sample-res-config.yaml /path/to/config.yaml$ vi /path/to/config.yaml
  1. Install
$ helm repo add infracloudio https://infracloudio.github.io/charts$ helm repo update$ helm install --version v0.12.4 botkube --namespace botkube \--set communications.webhook.enabled=true \--set communications.webhook.url=<WEBHOOK_URL> \--set config.settings.clustername=<CLUSTER_NAME> \--set image.repository=infracloudio/botkube \--set image.tag=v0.12.4 \-f /path/to/config.yamlinfracloudio/botkube
  1. Check the installation:
$ kubectl get-all -n botkubeNAME                                  NAMESPACE  AGEconfigmap/botkube-configmap           botkube    6d22hconfigmap/kube-root-ca.crt            botkube    6d22hpod/botkube-785d6c889-srbzg           botkube    6d22hsecret/botkube-communication-secret   botkube    6d22hsecret/botkube-sa-token-btjvj         botkube    6d22hsecret/default-token-d5s9n            botkube    6d22hsecret/sh.helm.release.v1.botkube.v1  botkube    6d22hserviceaccount/botkube-sa             botkube    6d22hserviceaccount/default                botkube    6d22hdeployment.apps/botkube               botkube    6d22hreplicaset.apps/botkube-785d6c889     botkube    6d22h

get-all is a krew plugin

Usage

Now when identified events are triggered, webhook url is POSTed with an appropriate json payload

$ kubectl logs -n botkube pod/botkube-785d6c889-srbzg...INFO[2022-04-09T13:27:26Z] Registering resource lifecycle informerINFO[2022-04-09T13:27:26Z] Adding informer for resource:apps/v1/deploymentsINFO[2022-04-09T13:27:26Z] Adding informer for resource:apps/v1/statefulsetsINFO[2022-04-09T13:27:26Z] Adding informer for resource:apps/v1/daemonsetsINFO[2022-04-09T13:27:26Z] Adding informer for resource:v1/nodesINFO[2022-04-09T13:27:26Z] Registering kubernetes events informer for types: warningINFO[2022-04-09T13:27:26Z] Registering kubernetes events informer for types: normalINFO[2022-04-09T13:27:26Z] Registering watcher on configfile /config/resource_config.yaml

Payloads will be like:

{    "meta": {        "cluster": "macbook-kind",        "kind": "Deployment",        "name": "test-dep4",        "namespace": "default"    },    "status": {        "level": "info",        "type": "create"    },    "summary": "Deployment *default/test-dep4* has been created in *macbook-kind* cluster
", "timestamp": "2022-04-12T00:38:15Z"}
Conclusion

botkube is capable of a lot more including building a full-fledged chatbot for managing kubernetes cluster and provides extension points as well. Do check-out the documentation

There is another similar project called kubewatch, but not active anymore


Original Link: https://dev.to/ashokan/notify-kubernetes-events-with-botkube-4896

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To