Skip to main content

K3s Kubernetes

BotKube

What is BotKube?

I was looking for something to monitor my Kubernetes cluster and send me messages to Slack or other chat services. First I come across Robusta which looks great, but does not have support for ARM64 (now 07/21/2022). I have raised a request for multi arch, but it can take some time. I looked for something similar and found BotKube.

What I wanted was nothing fancy like Grafana/Prometheus combo, I purposely disabled that part there. Just send me a message if something happens.  Both Robusta and BotKube can do that. Robusta is focusing on the alerting part, with option to enable cloud UI. BotKube on the other hand can also manage your Kubernetes cluster from slack. Like full on kubect commands. To be completely honest I disabled that part, that's a bit scary for me, for security reasons.

Install

I'm going to use it with Slack, but look at the official documentation for more integrations and options. Here is the link.

You do not need to do anything special to install BotKube, therefore I do not need to put the step-by-step instructions here. It's also early in development and stuff can change, so I will just provide a link to the official documentation. Here is the link.

All I did was to install it using Argo CD and put the helm parameters in Argo directly.  Just click the Add to Slack button and get yours bots token.

Then I edited these values of the helm chart:

  • communications.slack.channel: k3s-notifications - My private channel for notifications.
  • communications.slack.enabled: true - Enabling Slack communication
  • communications.slack.notiftype: long - Notification type. Long is more verbose, short is more concise.
  • communications.slack.tokenThat token from Add to Slack
  • config.settings.clustername:  rpi4cluster - Just name of the cluster, KubeBot can work with multiple clusters, so it's good idea to keep them named.
  • config.settings.kubectl.enabled: false - I do not want to use kubectl from slack, I see this as a security risk. But it can be useful for debuting from a phone.

I left the rest as it was. It comes pre-configured to monitor most of the Kubernetes resources. I needed to monitor pod errors, restarts and other events.

Once deployed:

Jump into your Slack app, and you should see the BotKube bot.

You need to create a channel for the bot you specified in communications.slack.channel and then add the bot to that channel. Right-click on the bot and select View app details then add it to your private channel.

That's pretty much it for setting up BotKube. You can type /botkubehelp in the channel to get a list of commands:

BotKube Help

Usage:
    @BotKube ping [--cluster-name <cluster-name>]
    @BotKube commands list  (on BotKube v0.11.0+)
    @BotKube <kubectl command without kubectl prefix> [--cluster-name <cluster_name>]
    @BotKube notifier [stop|start|status|showconfig]
    @BotKube filters [list|enable|disable] [filter-name]

Description:

Cluster Status:
    - List all available Kubernetes Clusters and check connection health.
    - If flag specified, gives response from the specified cluster.

    Example:
        @BotKube ping
        @BotKube ping --cluster-name mycluster

Allowed kubectl commands list:
    - Show allowed kubectl commands as per the BotKube configuration

    Example:
        @BotKube commands list

Kubectl commands:
    - Executes kubectl commands on k8s cluster and returns output.

    Example:
        @BotKube get pods
        @BotKube logs podname -n namespace
        @BotKube get deployment --cluster-name cluster_name

    Allowed kubectl commands:
        For BotKube v0.11.0+:
            Check allowed commands with '@BotKube commands list'
        For older versions:
            Allowed commands are - get, top, cluster-info, describe, explain, logs, version, auth, api-resources, api-versions, diff

Notifier commands:
    - Commands to manage incoming notifications (Runs only on configured channel).

    Example:
        @BotKube notifier stop          Stop sending k8s event notifications to Slack
        @BotKube notifier start         Start sending k8s event notifications to Slack
        @BotKube notifier status        Show running status of event notifier
        @BotKube notifier showconfig    Show BotKube configuration for event notifier

Filters commands:
    - Command to manage filters run on K8s events (Runs only on configured channel).

    Example:
        @BotKube filters list                     Show list of available filters
        @BotKube filters disable ImageTagChecker  Disable filter
        @BotKube filters enable ImageTagChecker   Enable filter

Options:
    --cluster-name                  Get cluster specific response

Since I disabled the kubectl commands, I can't use stuff like @BotKube get pods, but I will receive notification if something happens in the cluster now.

Here is an example how it looks like when I triggered deployment restart on my cluster and there was an error with PVC:

It continues down, but as you can see, the message was sent ok. I use Slack on phone, and can now be notified when something happens on cluster.

And that's it, this was not much of a guide, but a featurette and note for me that this exists. When I come back to rebuilding cluster, I can add it back again 😄