T4K Integration with Slack using BotKube

This section provides step by step instructions to install and configure BotKube to monitor T4K resources from Slack along with other native Kubernetes resources.

Introduction

In today's world, it's imperative to be able to receive notifications for your Kubernetes environments into communication and notification tools of choice. Slack is a new-age communication tool leveraged by a lot of different teams and organizations today. In order to keep a consistent user experience across ecosystem tools leveraged by T4K users, notifications can be supported within Slack for T4K resources through BotKube.

This page guides you with detailed instructions to install BotKube on a Kubernetes cluster, configure it to integrate with Slack, and monitor T4K resources to provide notifications around T4K activity within Slack channels directly.

What is BotKube

BotKube is a messaging bot for monitoring and debugging Kubernetes clusters. It can be integrated with multiple messaging platforms like - Slack, Mattermost, Microsoft Teams, Discord to help you monitor T4K resources and other Kubernetes resources.

Install and configure BotKube with Slack

Install BotKube App to Slack workspace

  1. Search for the BotKube application in the Apps section on Slack, install the application using the Add to Slack button provided.

  2. After you authorize the application, you will get a BOT Access token. Note down this token as it will be required during deployment of BotKube backend on Kubernetes cluster.

Add BotKube App as a user to Slack Channel

Once the BotKube application is installed to the Slack workspace, you can see BotKube user (@Botkube) present. Add this Botkube user to your slack channel from where you want to monitor the T4K resources.

Install BotKube backend in Kubernetes Cluster

  1. Add infracloudio chart repository to the Kubernetes cluster

helm repo add infracloudio https://infracloudio.github.io/charts
helm repo update

2. Install BotKube backend with required input parameters to configure Slack communication

helm install --version v0.12.1 botkube --namespace botkube \
  --set communications.slack.enabled=true \
  --set communications.slack.channel=<SLACK_CHANNEL_NAME> \
  --set communications.slack.token=<xoxb-SLACK_API_TOKEN_FOR_THE_BOT> \
  --set config.settings.clustername=<K8S_CLUSTER_NAME> \
  --set config.settings.kubectl.enabled=<ALLOW_KUBECTL_true_or_false>\
  --set image.repository=infracloudio/botkube \
  --set image.tag=v0.12.1 \
  infracloudio/botkube

3. Verify that the botkube controller pod is in running state

kubectl get pod -n botkube
NAME                     READY   STATUS    RESTARTS   AGE
botkube-6fdf477b-gskb7   1/1     Running   9          12d

After the above installation with default configuration, BotKube will watch all the resources in all the namespaces for create, delete and error events for configured Kubernetes cluster.

Configure T4K Resource Monitoring

  1. Along with default configurations, we will update the botkube-configmap with T4K custom resources for monitoring

kubectl get configmap -n botkube
NAME                DATA   AGE
botkube-configmap   1      14d
kube-root-ca.crt    1      15d

2. Add T4K custom resources to the BotKube configmap

kubectl edit configmap botkube-configmap -n botkube
apiVersion: v1
data:
  resource_config.yaml: |
    recommendations: true
    resources:
    - events:
      - all
      name: triliovault.trilio.io/v1/licenses
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/targets
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/policies
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/hooks
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/backupplans
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/backups
      namespaces:
        ignore:
        - null
        include:
         - all
    - events:
      - all
      name: triliovault.trilio.io/v1/restores
      namespaces:
        ignore:
        - null
        include:
         - all

The above configuration is for the Cluster scoped installation of T4K. We have specified to include all namespaces for notifications using the following syntax namespaces: -> include: -> -all

In the case of namespace scoped installation of T4K, you can include only the specific namespace where T4K is installed.

3. This update will start populating any operations done on the T4K resources.

Configure T4K Resource Commands to execute from Slack

  1. You can expand the list of commands that can be executed from slack directly onto the Kubernetes resources and T4K resources.

kubectl edit configmap botkube-configmap -n botkube

2. Add the commands that can be executed on the T4K resources along with the verbs under settings.kubectl.commands.resources and settings.kubectl.commands.verbs section

    settings:
      clustername: east-2-rke-120
      configwatcher: true
      kubectl:
        commands:
          resources:
          - deployments
          - pods
          - namespaces
          - daemonsets
          - statefulsets
          - storageclasses
          - nodes
          - licenses
          - policies
          - hooks
          - targets
          - backupplans
          - backups
          - restores
          - triliovaultmanagers
          verbs:
          - api-resources
          - api-versions
          - cluster-info
          - describe
          - diff
          - explain
          - get
          - logs
          - top
          - auth
          - create
          - get
          - edit
          - delete
        defaultNamespace: default

3. Once the Botkube configmap is updated, you can see the updated commands list from slack

Usage of commands and verbs

You can execute above commands directly from slack to monitor the T4K resources

Remove BotKube from Kubernetes cluster

We installed BotKube using helm, execute the following command to completely remove BotKube and related resources.

helm delete --purge botkube -n botkube

For integrations with other tools such as Mattermost, Microsoft Teams, Discord, Elastic Search configurations, users can follow BotKube documentations.

Last updated