前言
這次要介紹一個 Kubernetes 資源觀測工具誉裆,實(shí)時監(jiān)控 Kubernetes 集群中各種資源的新建、更新和刪除浅役,并實(shí)時通知到各種協(xié)作軟件/聊天軟件涛菠,目前支持的通知渠道有:
slack
hipchat
mattermost
flock
webhook
我這邊開發(fā)了釘釘?shù)耐ㄖ溃窃谏嫌?ISSUE#198 中提出的貢獻(xiàn)請求并沒有得到回應(yīng)瓶籽,所以這邊只能 fork 了代碼引润,然后自己進(jìn)行了開發(fā)十减,以支持釘釘通知告抄。
安裝
這里推薦使用 helm 進(jìn)行安裝撰茎,快速部署
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 包龄糊,可直接進(jìn)行安裝
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"
釘釘配置
在釘釘中創(chuàng)建 智能群助手
,之后
獲取 token
復(fù)制的 webhook 中 https://oapi.dingtalk.com/robot/send?access_token={YOUR_TOKEN}
, {YOUR_TOKEN}
就是要填入的 token募疮。
安全設(shè)置
釘釘智能群助手在更新后新增了安全設(shè)置炫惩,提供三種驗(yàn)證方式 自定義關(guān)鍵詞
加簽
IP地址(段)
,這里推薦使用 IP地址(段)的方式
阿浓,直接將 Kubernetes 集群的出口 IP 填入設(shè)置即可他嚷。同時也提供了 加簽
的方式,拷貝秘鑰搔扁,將其填入 dingtalk.sign
中爸舒。
項(xiàng)目配置
編輯 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 默認(rèn)的通知軟件稿蹲,這里就不簡介 Slack 的安裝和注冊,直接從創(chuàng)建 APP 開始
創(chuàng)建一個 APP
進(jìn)去創(chuàng)建 APP 頁面
選擇 App Name
和 Development Slack Workspace
添加 Bot 用戶
添加 App 到 Workspace
獲取 Bot-token
通知效果
在 Slack 中鹊奖,創(chuàng)建
更新
刪除
分別以綠苛聘、黃和紅色代表
在釘釘中,我進(jìn)行了漢化
結(jié)語
對于 kubewatch 我們這里主要用作監(jiān)控各種 CronJob 的定時觸發(fā)狀態(tài)忠聚,已經(jīng) ConfigMap 和 Secrets 的狀態(tài)變化设哗,同時也觀察 HPA 觸發(fā)的彈性伸縮的狀態(tài),可以實(shí)時觀測到業(yè)務(wù)高峰的到來两蟀,是一個不錯的小工具网梢。