Responsive

Tutorial: Streamlining GitOps with the Botkube Flux Plugin

Sep 1, 2023
10 mins
read
Maria Ashby
Developer Advocate
Botkube

Learn how to set up Botkube with Flux and GitHub-events plugins in this step-by-step tutorial. Configure permissions, insert tokens, and install seamlessly.

Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

In today's fast-paced world of Kubernetes management, embracing GitOps is a crucial step towards efficient collaboration and automation. However, it comes with its own set of challenges. Enter [Botkube](https://botkube.io/), a Kubernetes collaborative troubleshooting tool for Kubernetes that seamlessly integrates with popular collaboration platforms like [Slack, Microsoft Teams, Discord, and Mattermost](https://botkube.io/integrations). Botkube not only simplifies alert management but also optimizes GitOps workflows by enhancing automation, real-time collaboration and centralizing knowledge.  Learn more about Botkube’s move towards [GitOps](https://botkube.io/blog/enhancing-gitops-workflows-with-botkube) and the new Flux Plugin in our [release announcemen](https://botkube.io/blog/introducing-botkubes-integration-with-flux)t. In this tutorial, we will explore the Botkube Flux plugin, a powerful tool that automates notifications, enhances GitOps practices, and simplifies the interaction between Kubernetes clusters and GitHub repositories. By the end of this tutorial, you'll have a solid understanding of how to create, configure, and leverage the Botkube Flux plugin to streamline your GitOps workflow.

## Prerequisites

Before we dive into the tutorial, make sure you have the following prerequisites ready:

* A GitHub account with access to tokens
* Basic familiarity with Kubernetes and its components.
* Access to a Kubernetes cluster with helm installed
* Access to Slack workspace
* A Botkube Cloud Account

### Creating Botkube Cloud Account

1. On the Botkube [homepage](https://botkube.io/), locate the “Get Started” button and click on it. This will take you to the account registration page.
2. Fill in the required information in the registration form. You can sign up with your email address or Github account.

* Click [here](https://botkube.io/blog/step-by-step-tutorial-leveraging-botkubes-cloud-slack-feature-for-kubernetes-collaborative-troubleshooting) for a more indepth Botkube installation tutorial

Easy one click Kubernetes deployment for cloud


### Connecting Kubernetes Cluster to Slack

Select either the Wizard or the Block builder method to initiate the setup process for Botkube's Cloud Slack integration.

1. Next, enter your instance display name.

K8s cluster building GUI


2. Select the Official Botkube Slack option. (Note this option requires you to sign up for a 30 day free trial)

Official Slack Kubernetes bot

3. Access the app settings within Slack to configure the integration with Botkube. Click the "Add Slack" button to initiate the process.
4. Select the workspace within Slack where you want to utilize Botkube. You will now have access to public and private channels, enabling seamless communication and collaboration for Kubernetes troubleshooting tasks.

Multicluster setup screen for Slack

5. To include Botkube in private channels, utilize the "Add to Channel" feature. This ensures that Botkube is present in relevant channels where Kubernetes-related discussions and incident responses take place.

One click slack sign in

6. Select the Plugins you would like to use.

### Enabling the Plugin  

1. Select the Flux and GitHub-events Plugin

   * Begin by selecting the Flux and GitHub-events plugins within your Botkube setup.

2. Insert Your GitHub Access Token

   * To do this, navigate to your GitHub developer settings.

   * Locate your GitHub access token and copy it.

  * Insert the copied access token into the appropriate field within the Flux plugin settings.

3. Configure Permissions

  • In the Flux plugin settings, select the "Permissions" tab.
  • Choose the "Custom" option.
  • Under the custom permissions, select the "Group" option
  • Next, update the permissions for RBAC (Role-Based Access Control).
  • Add "flux-write" and "flux-read-patch" permissions since they are required for using the "flux install" command.

4. Configure GitHub-events Plugin

   * Now, select the GitHub-events plugin

5. Insert GitHub Access Token

   * Insert the same GitHub access token that you used for the Flux plugin into the GitHub-events plugin settings.

6. Repository Configuration

  • Scroll down to the "Repository Configuration" section.
  • Insert the name of your repository into the appropriate field.
  • Scroll further down to the "Pull Request Matcher" section.
  • Select the types of pull requests you want Botkube to check for.
  • For this demo, choose the "open" option.
  • In the same section, locate the "File Pattern" field.
  • Type in the file path that you want pull requests to match.
  • For this demo, use your "kustomize" folder.

7. Click the "Submit" button to save your configurations.

   * If desired, configure any additional plugins you want to use at this stage.

8. Click "Next" to proceed to the installation step.

9. On the next page, you will have the option to also enable [Command Alias](https://botkube.io/blog/command-line-magic-simplify-your-life-with-custom-kubernetes-kubectrl-aliases-on-botkube) and [Botkube Actions](https://docs.botkube.io/usage/automated-actions/).

   * Make your selection and click the create button.

10. You are now ready to start playing with your Botkube plugin.

## Using the Flux Plugin in Action

### Running a Flux install

With the Botkube Flux plugin, you have the power to streamline your Kubernetes deployment workflow even further. Beyond the ability to effortlessly manage GitHub pull requests, this plugin offers you the convenience of checking prerequisites on your cluster and performing a complete Flux installation – all from your preferred communication platform. This means that not only can you seamlessly collaborate with your team members by sharing and discussing pull request changes within your Slack channel, but you can also ensure that your cluster is properly configured before initiating the installation of Flux. This capability to validate prerequisites directly from your communication platform adds a layer of control and convenience to your Kubernetes operations.

### Automating a Flux Diff Workflow


This command streamlines several essential tasks in your workflow. It starts by automatically identifying the relevant GitHub repository linked to the provided kustomization. After that, it proceeds to clone this repository and check out a specified pull request. The command then performs a thorough comparison between the changes in the pull request and the current state of your cluster. What sets it apart is its ability to conveniently share the resulting diff report on your Slack channel, facilitating seamless collaboration among team members for reviewing and discussing the alterations. Moreover, the command enhances efficiency by offering additional contextual actions, including posting the diff report as a GitHub comment on the corresponding pull request, approving the pull request, and providing quick access to view the pull request itself. Combining Botkube's GitHub Slack integration for repo control and Flux CD integration for more tools allows for better GitOps workflow management.

## Conclusion

In conclusion, the Botkube Flux plugin presents an invaluable asset for simplifying GitOps workflows. From automating notifications to enhancing collaboration, this tool streamlines the process of managing Kubernetes clusters and GitHub repositories. We encourage you to implement the plugin in your workflow and explore further automation possibilities.With seamless integration into major communication channels, Botkube empowers you to take swift action on identified errors, ensuring your Kubernetes environment runs smoothly wherever you are.