How to Build a ChatOps-Bot with Slack and Kubernetes

How to Build a ChatOps-Bot with Slack and Kubernetes hackernoon.com3 months ago in #Dev Love20

ChatOps allows you to manage your DevOps tasks using chat based interfaces. Learn how to build a simple bot to control a Kubernetes cluster using Slack.  In the end you are able to view Kubernetes logs and info using Slack chat messages. No prior knowledge of Kubernetes, or the Slack API is necessary. So let’s get started building by exploring what ChatOps is. What is ChatOps ChatOps is a way to execute DevOps tasks, such as deployments, monitoring and system management using chat messages. For example sending a logs message to a chatbot retrieves the latest log messages. Or a deployment could be triggered from a chat message. This offers a few important advantages: A very human way to manage your infrastructure, by chatting with a bot. @chatbot logs is much easier to understand than kubectl logs hello-minikube-64b64df8c9-fkb6w -ndefault . It can be part of a shared chat, so that people can collaborate and share information. This also offers a record of executed commands and actions. It can help safely overcome network and firewall restrictions to make working from home or on the go possible. A unified interface over DevOps tools, manage Kubernetes and OpenShift with the same interfaceIt can simplify and secure infrastructure tasks, so they can be done by the developers themselves. Setup This article describes building a minimal chatbot using: Minikube as a Kubernetes environment. Kubernetes is labeled as a “Production-Grade Container Orchestration”. Kubernetes allows us to deploy, manage and scale docker images. Minikube is a turnkey solution for running Kubernetes on a dev machine. Slack as a chat server Python to implement the actual chat bot server. Minikube To quickly run Kubernetes on a develop machine, Minikube implements a Kubernetes cluster in a single virtual machine image. Detailed installation instructions can be found here. To install it on my macOs System I used VirtualBox as virtualization driver. VirtualBox can be found here.  After installing VirtualBox, Minikube can be installed on macOs using the commands below. It’ll also deploy a sample application. This assumes you have homebrew installed. brew install minikube # install via Homebrew minikube start – driver=virtualbox # start and use Virtualbox kubectl create deployment # install sample app To verify the installation use: kubectl get all and the result should show the example pod, something like pod/hello-minikube-64b64df8c9-fkb6w. A (incredibly) short introduction to Kubernetes Kubernetes is a software that allows the management of docker images in a cluster. This includes deployment, scaling, managing and monitoring. The base deployment unit is a Pod. Pods can contain multiple docker images or containers. The chatbot we will develop in this article only supports pods with a single image. Kubernetes can be controlled through the kubectl command and other means. Our server will use the following Kubernetes commands kubectl get pods –selector=app={app} –namespace={namespace}  : to retrieve the pods for an application in a namespace.  kubectl logs {pod} –namespace={namespace}  : to get the logs for a container in a pod (if only a single image is in a container) kubectl describe pod {pod} –namespace={namespace}  : to describe details about a pod.  Slack If you don’t have a Slack account you can get your own workspace at  » Read More

Like to keep reading?

This article first appeared on If you'd like to keep reading, follow the white rabbit.

View Full Article

Leave a Reply