# T4K Integration with Slack using BotKube

### 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.

![Search and install BotKube application on Slack](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/JBWGYUx6xjGa4y8bzbNR/image%20\(305\).png)

#### 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.

![BotKube user in Slack workspace](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/7kjEywd58otbN1wxR8Xt/tempsnip.png)

![Invite the BotKube user to Slack channel](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/1cL0KI0QRDCiXLQgU29Y/image%20\(256\).png)

### Install BotKube backend in Kubernetes Cluster

1. Add infracloudio chart repository to the Kubernetes cluster

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

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

```bash
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

```bash
kubectl get pod -n botkube
```

```bash
NAME                     READY   STATUS    RESTARTS   AGE
botkube-6fdf477b-gskb7   1/1     Running   9          12d
```

{% hint style="info" %}
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.
{% endhint %}

### 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
```

{% hint style="info" %}
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.
{% endhint %}

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

![T4K target resource is created](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/hJF8PoVpPN0SMwOrJK0i/image%20\(459\).png)

![T4K policy resource is created](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/nF0qgrR72ghFuSrOjUme/image%20\(119\).png)

### 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

![Commands lists on slack after updating the configmap](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/36okBTkDxYQ6JIvfBXmB/image%20\(178\).png)

### Usage of commands and verbs

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

![Get backupplan command execution from Slack](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/Djnk5gOkmb0dWrGnGpa4/image%20\(18\).png)

![Get backup command execution from Slack](https://content.gitbook.com/content/9sDjF5HJP1bf8TtLcgkk/blobs/2m9BEeZcAAs44fR6NkfN/image%20\(6\).png)

### 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](https://www.botkube.io/installation/).
