前言
这次要介绍一个 Kubernetes 资源观测工具,实时监控 Kubernetes 集群中各种资源的新建、更新和删除,并实时通知到各种协作软件/聊天软件,目前支持的通知渠道有:
slack
hipchat
mattermost
flock
webhook
我这边开发了钉钉的通知渠道,但是在上游 ISSUE#198 中提出的贡献请求并没有得到回应,所以这边只能 fork 了代码,然后自己进行了开发,以支持钉钉通知。
安装
这里推荐使用 helm 进行安装,快速部署
helm install kubewatch stable/kubewatch \
--set rbac.create=true \
--set slack.channel='#YOUR_CHANNEL' \
--set slack.token='xoxb-YOUR_TOKEN' \
--set resourcesToWatch.pod=true \
--set resourcesToWatch.daemonset=true
如果想使用钉钉通知,则可以在 GitHub 上拉取我的代码,代码中包含 helm chart 包,可直接进行安装
git clone https://github.com/sunny0826/kubewatch-chat.git
cd kubewatch-chat
helm install kubewatch kubewatch \
--set dingtalk.sign="XXX" \
--set dingtalk.token="XXXX-XXXX-XXXX"
钉钉配置
在钉钉中创建 智能群助手
,之后
获取 token
复制的 webhook 中 https://oapi.dingtalk.com/robot/send?access_token={YOUR_TOKEN}
, {YOUR_TOKEN}
就是要填入的 token。
安全设置
钉钉智能群助手在更新后新增了安全设置,提供三种验证方式 自定义关键词
加签
IP地址(段)
,这里推荐使用 IP地址(段)的方式
,直接将 Kubernetes 集群的出口 IP 填入设置即可。同时也提供了 加签
的方式,拷贝秘钥,将其填入 dingtalk.sign
中。
项目配置
编辑 kubewatch/value.yaml
,修改配置
## Global Docker image parameters
## Please, note that this will override the image parameters, including dependencies, configured to use the global value
## Current available global Docker image parameters: imageRegistry and imagePullSecrets
##
# global:
# imageRegistry: myRegistryName
# imagePullSecrets:
# - myRegistryKeySecretName
slack:
enabled: false
channel: ""
token: "xoxb"
hipchat:
enabled: false
# room: ""
# token: ""
# url: ""
mattermost:
enabled: false
# channel: ""
# url: ""
# username: ""
flock:
enabled: false
# url: ""
webhook:
enabled: false
# url: ""
dingtalk:
enabled: true
token: ""
sign: ""
# namespace to watch, leave it empty for watching all.
namespaceToWatch: ""
# Resources to watch
resourcesToWatch:
deployment: true
replicationcontroller: false
replicaset: false
daemonset: false
services: false
pod: true
job: false
persistentvolume: false
image:
registry: docker.io
# repository: bitnami/kubewatch
repository: guoxudongdocker/kubewatch-chart
# tag: 0.0.4-debian-9-r405
tag: latest
pullPolicy: Always
## Optionally specify an array of imagePullSecrets.
## Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
##
# pullSecrets:
# - myRegistryKeySecretName
## String to partially override kubewatch.fullname template (will maintain the release name)
##
# nameOverride:
## String to fully override kubewatch.fullname template
##
# fullnameOverride:
rbac:
# If true, create & use RBAC resources
#
create: true
serviceAccount:
# Specifies whether a ServiceAccount should be created
create: true
# The name of the ServiceAccount to use.
# If not set and create is true, a name is generated using the fullname template
name:
resources: {}
# limits:
# cpu: 100m
# memory: 300Mi
# requests:
# cpu: 100m
# memory: 300Mi
# Affinity for pod assignment
# Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
# affinity: {}
# Tolerations for pod assignment
# Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
tolerations: []
# Node labels for pod assignment
# Ref: https://kubernetes.io/docs/user-guide/node-selection/
nodeSelector: {}
podAnnotations: {}
podLabels: {}
replicaCount: 1
使用 value.yaml
安装
git clone https://github.com/sunny0826/kubewatch-chat.git
cd kubewatch-chat
helm install my-release -f kubewatch/values.yaml
Slack 配置
Slack 为 kubewatch 默认的通知软件,这里就不简介 Slack 的安装和注册,直接从创建 APP 开始
创建一个 APP
进去创建 APP 页面
选择 App Name
和 Development Slack Workspace
添加 Bot 用户
添加 App 到 Workspace
获取 Bot-token
通知效果
在 Slack 中,创建
更新
删除
分别以绿、黄和红色代表
在钉钉中,我进行了汉化
结语
对于 kubewatch 我们这里主要用作监控各种 CronJob 的定时触发状态,已经 ConfigMap 和 Secrets 的状态变化,同时也观察 HPA 触发的弹性伸缩的状态,可以实时观测到业务高峰的到来,是一个不错的小工具。
5 Comments
OLanecax
#HeLLo#
I was able to find good info from your blog posts.
Turkey SMS virtual number
Ismaelfrive
Everything wrote was very reasonable. However, think on this, suppose you typed a catchier title? I mean, I don’t want to tell you how to run your blog, but suppose you added a title that makes people want more? I mean %BLOG_TITLE% is kinda plain. You could look at Yahoo’s home page and see how they create article headlines to get viewers to click. You might add a video or a related pic or two to get readers excited about what you’ve written. Just my opinion, it could bring your posts a little bit more interesting.
https://amato.com.ua/yak-vybraty-najkrashche-sklo-dlya-far-avtomobilya.html
EarnestSak
Why viewers still use to read news papers when in this technological globe all is presented on net?
https://gmailspva.com/germetyk-dlya-far-koly-i-yak-vykorystovuvaty
Fobertjuics
May I just say what a relief to discover someone who truly understands what they’re talking about on the web. You definitely realize how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I can’t believe you aren’t more popular since you certainly possess the gift.
https://flytime24.us/plinko-game-online-strategies-mastering-the-digita.html
Ismaelfrive
Hi, all is going fine here and ofcourse every one is sharing information, that’s really good, keep up writing.
http://getxtnd.com/plinko-frenzy-a-guide-to-playing-and-winning.html