BotKube BotKube 是一个用于监控和调试 Kubernetes 集群的消息传递工具。 BotKube 可以与多个消息传递平台(如 Slack、Mattermost 或 Microsoft Teams)集成,以帮助您监控 Kubernetes 集群、调试关键部署
BotKube
BotKube 是一个用于监控和调试 Kubernetes 集群的消息传递工具。 BotKube 可以与多个消息传递平台(如 Slack、Mattermost 或 Microsoft Teams)集成,以帮助您监控 Kubernetes 集群、调试关键部署,并通过对 Kubernetes 资源运行检查来提供标准实践建议。
安装BotKube
1、本文使用slack作为消息接收平台,需要自行注册slack,拿到Access token
xoxb-2169032185141-2256603089394-qeLWxe0sUtwfdlwnk6VWbw112、将 BotKube 用户添加到 Slack 频道
将 BotKube 应用程序安装到您的 Slack 工作区后,您会看到一个名为“BotKube”的新机器人用户添加到您的工作区中。 将该机器人添加到您想要接收通知的 Slack 频道。
(您可以通过在频道中邀请@BotKube 来添加它)
3、使用helm把BotKube安装到kubernrtes集群
helm repo add infracloudio https://infracloudio.github.io/chartshelm repo update
请自行替换<>内的信息:
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=<SLACK_API_TOKEN_FOR_THE_BOT> \
--set config.settings.clustername=<CLUSTER_NAME> \
--set config.settings.kubectl.enabled=<ALLOW_KUBECTL> \
--set image.repository=infracloudio/botkube \
--set image.tag=v0.12.1 \
infracloudio/botkube
- SLACK_CHANNEL_NAME 是添加@BotKube 的频道名称
- SLACK_API_TOKEN_FOR_THE_BOT 是将 BotKube 应用程序安装到 Slack 工作区后收到的令牌
- CLUSTER_NAME 是在传入消息中设置的集群名称
- ALLOW_KUBECTL 设置为 true 以允许 BotKube 在集群上执行 kubectl 命令
4、查看安装信息
# helm list -n botkubeNAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
botkube botkube 1 2021-07-09 10:41:35.813245746 +0800 CST deployed botkube-v0.12.1 v0.12.1
# kubectl get all -n botkube
NAME READY STATUS RESTARTS AGE
pod/botkube-747ff4dc5d-795hz 1/1 Running 0 2d22h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/botkube 1/1 1 1 2d22h
NAME DESIRED CURRENT READY AGE
replicaset.apps/botkube-747ff4dc5d 1 1 1 2d22h
5、如果你需要修改配置,可以更新botkube-configmap,默认设置如下
recommendations: trueresources:
- events:
- create
- delete
- error
name: v1/pods
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/services
namespaces:
ignore:
- null
include:
- all
- events:
- create
- update
- delete
- error
name: apps/v1/deployments
namespaces:
ignore:
- null
include:
- all
updateSetting:
fields:
- spec.template.spec.containers[*].image
- status.availableReplicas
includeDiff: true
- events:
- create
- update
- delete
- error
name: apps/v1/statefulsets
namespaces:
ignore:
- null
include:
- all
updateSetting:
fields:
- spec.template.spec.containers[*].image
- status.readyReplicas
includeDiff: true
- events:
- create
- delete
- error
name: networking.k8s.io/v1beta1/ingresses
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/nodes
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/namespaces
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/persistentvolumes
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/persistentvolumeclaims
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: v1/configmaps
namespaces:
ignore:
- null
include:
- all
- events:
- create
- update
- delete
- error
name: apps/v1/daemonsets
namespaces:
ignore:
- null
include:
- all
updateSetting:
fields:
- spec.template.spec.containers[*].image
- status.numberReady
includeDiff: true
- events:
- create
- update
- delete
- error
name: batch/v1/jobs
namespaces:
ignore:
- null
include:
- all
updateSetting:
fields:
- spec.template.spec.containers[*].image
- status.conditions[*].type
includeDiff: true
- events:
- create
- delete
- error
name: rbac.authorization.k8s.io/v1/roles
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: rbac.authorization.k8s.io/v1/rolebindings
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: rbac.authorization.k8s.io/v1/clusterrolebindings
namespaces:
ignore:
- null
include:
- all
- events:
- create
- delete
- error
name: rbac.authorization.k8s.io/v1/clusterroles
namespaces:
ignore:
- null
include:
- all
settings:
clustername: k8s-2
configwatcher: true
kubectl:
commands:
resources:
- deployments
- pods
- namespaces
- daemonsets
- statefulsets
- storageclasses
- nodes
verbs:
- api-resources
- api-versions
- cluster-info
- describe
- diff
- explain
- get
- logs
- top
- auth
- describe
defaultNamespace:
- default
- pro
- qa
enabled: true
restrictAccess: false
upgradeNotifier: true
ssl:
enabled: false
使用Slack与BotKube对话
1、先ping下BotKube,看看输出
2、查看可使用的命令
3、以对话的形式执行kubectl命令,例如获取pod,更多命令可以自己测试…
4、验证slack收集kubernetes事件信息,例如创建一个新的pod,这里以nginx为例
我这里直接用lens连接集群,创建一个名为nginx的deployment,
直接创建即可,然后来到slack可以看到如下信息,即botkube将这个create事件消息推送到了你的slack频道。
现在删除deployment,再看slack频道,收到delete的消息
更多好玩的功能,请自行体会吧。。。