BotKube
BotKube 是一个用于监控和调试 Kubernetes 集群的消息传递工具。 BotKube 可以与多个消息传递平台(如 Slack、Mattermost 或 Microsoft Teams)集成,以帮助您监控 Kubernetes 集群、调试关键部署,并通过对 Kubernetes 资源运行检查来提供标准实践建议。
安装BotKube
1、本文使用slack作为消息接收平台,需要自行注册slack,拿到Access token
xoxb-2169032185141-2256603089394-qeLWxe0sUtwfdlwnk6VWbw11
- 1.
2、将 BotKube 用户添加到 Slack 频道
将 BotKube 应用程序安装到您的 Slack 工作区后,您会看到一个名为“BotKube”的新机器人用户添加到您的工作区中。 将该机器人添加到您想要接收通知的 Slack 频道。
(您可以通过在频道中邀请@BotKube 来添加它)
3、使用helm把BotKube安装到kubernrtes集群
helm repo add infracloudio https://infracloudio.github.io/charts
helm 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 命令
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
4、查看安装信息
# helm list -n botkube
NAME 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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
5、如果你需要修改配置,可以更新botkube-configmap,默认设置如下
recommendations: true
resources:
- 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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
使用Slack与BotKube对话
1、先ping下BotKube,看看输出
2、查看可使用的命令
3、以对话的形式执行kubectl命令,例如获取pod,更多命令可以自己测试…
4、验证slack收集kubernetes事件信息,例如创建一个新的pod,这里以nginx为例
我这里直接用lens连接集群,创建一个名为nginx的deployment,
直接创建即可,然后来到slack可以看到如下信息,即botkube将这个create事件消息推送到了你的slack频道。
现在删除deployment,再看slack频道,收到delete的消息
更多好玩的功能,请自行体会吧。。。