k8s系統,異常通知對接釘釘系統

萬公子發表於2020-12-08

1:首先在釘釘系統中自定義機器人記住webhoodk地址和自定義關鍵字,點選完成
在這裡插入圖片描述
2:建立test.ymal 檔案,複製如下內容,修改webhook 地址,以及帶上後面的引數
—sink=dingtalk:https:************&label=cluster1&level=Warning#釘釘對接的呼叫介面
label為對應的關鍵字,levle為對應的訊息級別。如果需要監控具體的某個名稱空間可以帶上&namespaces=“要監控的資源空間”


apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    name: kube-eventer
  name: kube-eventer
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kube-eventer
  template:
    metadata:
      labels:
        app: kube-eventer
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      dnsPolicy: ClusterFirstWithHostNet
      serviceAccount: kube-eventer
      containers:
        - image: registry.aliyuncs.com/acs/kube-eventer-amd64:v1.1.0-63e7f98-aliyun
          name: kube-eventer
          command:
            - "/kube-eventer"
            - "--source=kubernetes:https://kubernetes.default"
            ## .e.g,dingtalk sink demo
            - --sink=dingtalk:https://oapi.dingtalk.com/robot/send?access_token=340accbd0a10c1517ac511f9b0944b3f3c20d8cd7b319116xxxxxxxxxxxx&label=cluster1&level=Warning#釘釘對接的呼叫介面
          env:
          # If TZ is assigned, set the TZ value as the time zone
          - name: TZ
            value: Asia/Shanghai
          volumeMounts:
            - name: localtime
              mountPath: /etc/localtime
              readOnly: true
            - name: zoneinfo
              mountPath: /usr/share/zoneinfo
              readOnly: true
          resources:
            requests:
              cpu: 100m
              memory: 100Mi
            limits:
              cpu: 500m
              memory: 250Mi
      volumes:
        - name: localtime
          hostPath:
            path: /etc/localtime
        - name: zoneinfo
          hostPath:
            path: /usr/share/zoneinfo
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: kube-eventer
rules:
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
  name: kube-eventer
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kube-eventer
subjects:
  - kind: ServiceAccount
    name: kube-eventer
    namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kube-eventer
  namespace: kube-system

3:登入k8s伺服器後臺,將檔案傳到伺服器上,輸入命令
kubectl apply -f test.yaml
在這裡插入圖片描述

4:當有節點異常時,會自動推送訊息。通過檢視大約30秒推送一次。
k8s 追蹤日誌
在這裡插入圖片描述

在這裡插入圖片描述

相關文章