avatarSamuel Addico

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2800

Abstract

js-attr">bot:</span> <span class="hljs-bullet">-</span> <span class="hljs-string">channels:read</span> <span class="hljs-bullet">-</span> <span class="hljs-string">app_mentions:read</span> <span class="hljs-bullet">-</span> <span class="hljs-string">chat:write</span> <span class="hljs-bullet">-</span> <span class="hljs-string">files:write</span> <span class="hljs-attr">settings:</span> <span class="hljs-attr">event_subscriptions:</span> <span class="hljs-attr">bot_events:</span> <span class="hljs-bullet">-</span> <span class="hljs-string">app_mention</span> <span class="hljs-attr">interactivity:</span> <span class="hljs-attr">is_enabled:</span> <span class="hljs-literal">true</span> <span class="hljs-attr">org_deploy_enabled:</span> <span class="hljs-literal">false</span> <span class="hljs-attr">socket_mode_enabled:</span> <span class="hljs-literal">true</span> <span class="hljs-attr">token_rotation_enabled:</span> <span class="hljs-literal">false</span></pre></div><ul><li>Assuming you’re not an administrator, send a request to install the app.</li></ul><figure id="2ae4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*KCDsxWKaQA5V4W9fc_6nBQ.png"><figcaption></figcaption></figure><ul><li>Once approval is granted and the app is created, you need to get the bot token which should be saved for later. Select <b>OAuth & Permissions</b> section on the left sidebar. On this page, you can copy the bot token which starts with <code>xoxb...</code>.</li></ul><figure id="96a8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*LaO0G9VJ_0GZYZ7KLPUXMg.png"><figcaption></figcaption></figure><ul><li>Export Slack Bot Token as follows.</li></ul><div id="9091"><pre><span class="hljs-built_in">export</span> SLACK_API_BOT_TOKEN=<span class="hljs-string">"{botToken}"</span></pre></div><ul><li>Generate and obtain App-Level Token. To establish a WebSocket connection, a Slack App that uses Socket Mode necessitates an App-Level Token. To create an App-Level Token, adhere to the instructions below:</li><li>Click on the <b>Basic Information</b> link on the left sidebar, and navigate to the <b>App-Level Token</b> section. Next, select the <b>Generate Token</b> <b>and Scopes</b> button.</li><li>Provide a name, choose the<b> connections:write</b> sc-ope, and then click on the <b>Generate</b> button.</li></ul><figure id="97d5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*qPckclQOc1uPxsK7HaWyMQ.png"><figcaption></figcaption></figure><h2 id="937c">Install Botkube in your Kubernetes cluster</h2><p id="6010">To install Botkube, you will need to have Helm installed. You can follow this <a href="https://helm.sh/docs/intro/">guide</a> to install Helm</p><ul><li>Add Botkube chart reposi

Options

tory:</li></ul><div id="5af9"><pre>helm repo add botkube https://charts.botkube.io helm repo update</pre></div><ul><li>Create Environment Variable</li></ul><div id="2187"><pre>export CLUSTER_NAME={cluster_name} export ALLOW_KUBECTL={allow_kubectl} export ALLOW_HELM={allow_helm} export SLACK_CHANNEL_NAME={channel_name}</pre></div><ul><li><code>SLACK_CHANNEL_NAME</code> is the channel the bot will be added.</li><li><code>SLACK_API_BOT_TOKEN</code> is automatically generated when you installed the app in your workspace. You can use these to authenticate your app.</li><li><code>SLACK_API_APP_TOKEN</code> allows the app to use platform features that apply to multiple (or all) installations. It can be generated from Slack after installing the app in your workspace. <b><i>Basic Information > App-Level Tokens</i></b></li><li><code>CLUSTER_NAME</code> is the cluster name.</li><li><code>ALLOW_KUBECTL</code> determines whether or not to allow Botkube to run <code>kubectl</code> commands.</li><li><code>ALLOW_HELM</code> determines whether or not to allow Botkube to run <code>helm</code> commands.</li></ul><p id="432e">And finally the installation 🚀</p><div id="1f8b"><pre>helm install --version v0.18.0 botkube --namespace botkube --create-namespace
--<span class="hljs-built_in">set</span> communications.default-group.socketSlack.enabled=<span class="hljs-literal">true</span>
--<span class="hljs-built_in">set</span> communications.default-group.socketSlack.channels.default.name=<span class="hljs-variable">{SLACK_CHANNEL_NAME}</span> \ --<span class="hljs-built_in">set</span> communications.default-group.socketSlack.appToken=<span class="hljs-variable">{SLACK_API_APP_TOKEN}</span>
--<span class="hljs-built_in">set</span> communications.default-group.socketSlack.botToken=<span class="hljs-variable">{SLACK_API_BOT_TOKEN}</span> \ --<span class="hljs-built_in">set</span> settings.clusterName=<span class="hljs-variable">{CLUSTER_NAME}</span>
--<span class="hljs-built_in">set</span> executors.kubectl-read-only.kubectl.enabled=<span class="hljs-variable">{ALLOW_KUBECTL}</span> \ --<span class="hljs-built_in">set</span> <span class="hljs-string">'executors.helm.botkube/helm.enabled'</span>=<span class="hljs-variable">{ALLOW_HELM}</span>
botkube/botkube</pre></div><p id="7a2c">Once you have completed these steps, your chatbot will be set up and ready to use. Whenever a deployment occurs in your cluster, you will receive a notification in Slack with details about the deployment.</p><p id="d6b3">Using Botkube and Slack for deployment monitoring is a convenient and efficient way to keep track of changes to your system. It can help you stay up-to-date with what’s happening in your cluster and quickly respond to any issues that may arise.</p></article></body>

How to use Botkube to monitor Kubernetes Cluster

Introduction

In this tutorial, we will learn how to use Botkube and Slack for deployment monitoring in Kubernetes. By the end of this tutorial, you will be able to receive notifications in Slack whenever a deployment or update occurs in your Kubernetes cluster.

Prerequisites

  • Helm
  • Kubernetes cluster
  • Slack Account

What is Botkube?

Botkube is an open-source chatbot that helps developers monitor and manage their Kubernetes clusters. It can be integrated with popular chat platforms like Slack, allowing you to receive notifications and perform actions directly from your chat window.

One way to use Botkube and Slack for deployment monitoring is to set up the bot to notify you when a deployment occurs in your cluster. This can be helpful for keeping track of changes to your system and ensuring that deployments are running smoothly.

Create Slack App

We first need to create a Slack bot and obtain the bot token.

  • Navigate to the Slack App console to create a Slack app.
  • Click Create New App and select From an app manifest in the popup to create an application from the manifest.
  • Next, select a workspace where you want to create the app and click Next.
  • Under the YAML tab, copy and paste the following manifests, click Next, and then Create.
display_information:
  name: Botkube
  description: Botkube
  background_color: "#a653a6"
features:
  bot_user:
    display_name: Botkube
    always_online: false
oauth_config:
  scopes:
    bot:
      - channels:read
      - app_mentions:read
      - chat:write
      - files:write
settings:
  event_subscriptions:
    bot_events:
      - app_mention
  interactivity:
    is_enabled: true
  org_deploy_enabled: false
  socket_mode_enabled: true
  token_rotation_enabled: false
  • Assuming you’re not an administrator, send a request to install the app.
  • Once approval is granted and the app is created, you need to get the bot token which should be saved for later. Select OAuth & Permissions section on the left sidebar. On this page, you can copy the bot token which starts with xoxb....
  • Export Slack Bot Token as follows.
export SLACK_API_BOT_TOKEN="{botToken}"
  • Generate and obtain App-Level Token. To establish a WebSocket connection, a Slack App that uses Socket Mode necessitates an App-Level Token. To create an App-Level Token, adhere to the instructions below:
  • Click on the Basic Information link on the left sidebar, and navigate to the App-Level Token section. Next, select the Generate Token and Scopes button.
  • Provide a name, choose the connections:write sc-ope, and then click on the Generate button.

Install Botkube in your Kubernetes cluster

To install Botkube, you will need to have Helm installed. You can follow this guide to install Helm

  • Add Botkube chart repository:
helm repo add botkube https://charts.botkube.io
helm repo update
  • Create Environment Variable
export CLUSTER_NAME={cluster_name}
export ALLOW_KUBECTL={allow_kubectl}
export ALLOW_HELM={allow_helm}
export SLACK_CHANNEL_NAME={channel_name}
  • SLACK_CHANNEL_NAME is the channel the bot will be added.
  • SLACK_API_BOT_TOKEN is automatically generated when you installed the app in your workspace. You can use these to authenticate your app.
  • SLACK_API_APP_TOKEN allows the app to use platform features that apply to multiple (or all) installations. It can be generated from Slack after installing the app in your workspace. Basic Information > App-Level Tokens
  • CLUSTER_NAME is the cluster name.
  • ALLOW_KUBECTL determines whether or not to allow Botkube to run kubectl commands.
  • ALLOW_HELM determines whether or not to allow Botkube to run helm commands.

And finally the installation 🚀

helm install --version v0.18.0 botkube --namespace botkube --create-namespace \
--set communications.default-group.socketSlack.enabled=true \
--set communications.default-group.socketSlack.channels.default.name=${SLACK_CHANNEL_NAME} \
--set communications.default-group.socketSlack.appToken=${SLACK_API_APP_TOKEN} \
--set communications.default-group.socketSlack.botToken=${SLACK_API_BOT_TOKEN} \
--set settings.clusterName=${CLUSTER_NAME} \
--set executors.kubectl-read-only.kubectl.enabled=${ALLOW_KUBECTL} \
--set 'executors.helm.botkube/helm.enabled'=${ALLOW_HELM} \
botkube/botkube

Once you have completed these steps, your chatbot will be set up and ready to use. Whenever a deployment occurs in your cluster, you will receive a notification in Slack with details about the deployment.

Using Botkube and Slack for deployment monitoring is a convenient and efficient way to keep track of changes to your system. It can help you stay up-to-date with what’s happening in your cluster and quickly respond to any issues that may arise.

Kubernetes
Monitoring
Botkube
Slack
DevOps
Recommended from ReadMedium