最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IoT邊緣集群Kubernetes?Events告警通知實現(xiàn)示例

 更新時間:2023年02月17日 11:13:32   作者:東風微鳴  
這篇文章主要為大家介紹了IoT邊緣集群Kubernetes?Events告警通知實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

背景

邊緣集群(基于 樹莓派 + K3S) 需要實現(xiàn)基本的告警功能。

邊緣集群限制

CPU/內存/存儲 資源緊張,無法支撐至少需要 2GB 以上內存和大量存儲的基于 Prometheus 的完整監(jiān)控體系方案(即使是基于 Prometheus Agent, 也無法支撐) (需要避免額外的存儲和計算資源消耗)

網絡條件,無法支撐監(jiān)控體系,因為監(jiān)控體系一般都需要每 1min 定時(或每時每刻)傳輸數(shù)據(jù),且數(shù)據(jù)量不?。?/p>

存在 5G 收費網絡的情況,且訪問的目的端地址需要開通權限,且按照流量收費,且因為 5G 網絡條件,網絡傳輸能力受限,且不穩(wěn)定(可能會在一段時間內離線);

關鍵需求

總結下來,關鍵需求如下:

  • 實現(xiàn)對邊緣集群異常的及時告警,需要知道邊緣集群正在發(fā)生的異常情況;
  • 網絡:網絡條件情況較差,網絡流量少,只只能開通極少數(shù)目的端地址,可以容忍網絡不穩(wěn)定(一段時間內離線)的情況;
  • 資源:需要盡量避免額外的存儲和計算資源消耗

方案

綜上所訴,采用如下方案實現(xiàn):

基于 Kubernetes Events 的告警通知

架構圖

技術方案規(guī)劃

  • 從 Kubernetes 的各項資源收集 Events, 如:

    pod

    node

    kubelet

    crd

    ...

  • 通過 kubernetes-event-exporter 組件來實現(xiàn)對 Kubernetes Events 的收集;
  • 只篩選 Warning 級別 Events 供告警通知(后續(xù),條件可以進一步定義)
  • 告警通過 飛書 webhook 等通信工具進行發(fā)送(后續(xù),發(fā)送渠道可以增加)

實施步驟

手動方式:

在邊緣集群上,執(zhí)行如下操作:

1. 創(chuàng)建 roles

如下:

cat << _EOF_ | kubectl apply -f -
---
apiVersion: v1
kind: Namespace
metadata:
  name: monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: event-exporter-extra
rules:
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
---
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: monitoring
  name: event-exporter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
  - kind: ServiceAccount
    namespace: monitoring
    name: event-exporter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter-extra
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: event-exporter-extra
subjects:
  - kind: ServiceAccount
    namespace: kube-event-export
    name: event-exporter
_EOF_

2. 創(chuàng)建 kubernetes-event-exporter config

如下:

cat &lt;&lt; _EOF_ | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: event-exporter-cfg
  namespace: monitoring
data:
  config.yaml: |
    logLevel: error
    logFormat: json
    route:
      routes:
        - match:
            - receiver: "dump"      
        - drop:
            - type: "Normal"
          match:
            - receiver: "feishu"                     
    receivers:
      - name: "dump"
        stdout: {}
      - name: "feishu"
        webhook:
          endpoint: "https://open.feishu.cn/open-apis/bot/v2/hook/..."
          headers:
            Content-Type: application/json
          layout:
            msg_type: interactive
            card:
              config:
                wide_screen_mode: true
                enable_forward: true
              header:
                title:
                  tag: plain_text
                  content: XXX IoT K3S 集群告警
                template: red
              elements:
                - tag: div
                  text: 
                    tag: lark_md
                    content: "**EventType:**  {{ .Type }}\n**EventKind:**  {{ .InvolvedObject.Kind }}\n**EventReason:**  {{ .Reason }}\n**EventTime:**  {{ .LastTimestamp }}\n**EventMessage:**  {{ .Message }}"
_EOF_

?? 注意:

  • endpoint: "https://open.feishu.cn/open-apis/bot/v2/hook/..." 按需修改為對應的 webhook endpoint, ?切記勿對外公布!!!
  • content: XXX IoT K3S 集群告警: 按需調整為方便快速識別的名稱,如:"家里測試 K3S 集群告警"

3. 創(chuàng)建 Deployment

cat &lt;&lt; _EOF_ | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: event-exporter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: event-exporter
      version: v1
  template:
    metadata:
      labels:
        app: event-exporter
        version: v1
    spec:
      volumes:
        - name: cfg
          configMap:
            name: event-exporter-cfg
            defaultMode: 420
        - name: localtime
          hostPath:
            path: /etc/localtime
            type: ''
        - name: zoneinfo
          hostPath:
            path: /usr/share/zoneinfo
            type: ''
      containers:
        - name: event-exporter
          image: ghcr.io/opsgenie/kubernetes-event-exporter:v0.11
          args:
            - '-conf=/data/config.yaml'
          env:
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: cfg
              mountPath: /data
            - name: localtime
              readOnly: true
              mountPath: /etc/localtime
            - name: zoneinfo
              readOnly: true
              mountPath: /usr/share/zoneinfo
          imagePullPolicy: IfNotPresent
      serviceAccount: event-exporter
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/controlplane
                    operator: In
                    values:
                      - 'true'
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/control-plane
                    operator: In
                    values:
                      - 'true'
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/master
                    operator: In
                    values:
                      - 'true'    
      tolerations:
        - key: node-role.kubernetes.io/controlplane
          value: 'true'
          effect: NoSchedule
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule
        - key: node-role.kubernetes.io/master
          operator: Exists
          effect: NoSchedule      
_EOF_

?? 說明:

  • event-exporter-cfg 相關配置,是用于加載以 ConfigMap 形式保存的配置文件;
  • localtime zoneinfo TZ 相關配置,是用于修改該 pod 的時區(qū)為Asia/Shanghai, 以使得最終顯示的通知效果為 CST 時區(qū);
  • affinity tolerations 相關配置,是為了確保:無論如何,優(yōu)先調度到 master node 上去,按需調整,此處是因為 master 往往在邊緣集群中作為網關存在,配置較高,且在線時間較長;

自動化部署

效果:安裝 K3S 時就自動部署

在 K3S server 所在節(jié)點,/var/lib/rancher/k3s/server/manifests/ 目錄(如果沒有該目錄就先創(chuàng)建)下,創(chuàng)建 event-exporter.yaml

---
apiVersion: v1
kind: Namespace
metadata:
  name: monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: event-exporter-extra
rules:
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
---
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: monitoring
  name: event-exporter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
  - kind: ServiceAccount
    namespace: monitoring
    name: event-exporter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter-extra
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: event-exporter-extra
subjects:
  - kind: ServiceAccount
    namespace: kube-event-export
    name: event-exporter
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: event-exporter-cfg
  namespace: monitoring
data:
  config.yaml: |
    logLevel: error
    logFormat: json
    route:
      routes:
        - match:
            - receiver: "dump"      
        - drop:
            - type: "Normal"
          match:
            - receiver: "feishu"                     
    receivers:
      - name: "dump"
        stdout: {}
      - name: "feishu"
        webhook:
          endpoint: "https://open.feishu.cn/open-apis/bot/v2/hook/dc4fd384-996b-4d20-87cf-45b3518869ec"
          headers:
            Content-Type: application/json
          layout:
            msg_type: interactive
            card:
              config:
                wide_screen_mode: true
                enable_forward: true
              header:
                title:
                  tag: plain_text
                  content: xxxK3S集群告警
                template: red
              elements:
                - tag: div
                  text: 
                    tag: lark_md
                    content: "**EventType:**  {{ .Type }}\n**EventKind:**  {{ .InvolvedObject.Kind }}\n**EventReason:**  {{ .Reason }}\n**EventTime:**  {{ .LastTimestamp }}\n**EventMessage:**  {{ .Message }}"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: event-exporter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: event-exporter
      version: v1
  template:
    metadata:
      labels:
        app: event-exporter
        version: v1
    spec:
      volumes:
        - name: cfg
          configMap:
            name: event-exporter-cfg
            defaultMode: 420
        - name: localtime
          hostPath:
            path: /etc/localtime
            type: ''
        - name: zoneinfo
          hostPath:
            path: /usr/share/zoneinfo
            type: ''
      containers:
        - name: event-exporter
          image: ghcr.io/opsgenie/kubernetes-event-exporter:v0.11
          args:
            - '-conf=/data/config.yaml'
          env:
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: cfg
              mountPath: /data
            - name: localtime
              readOnly: true
              mountPath: /etc/localtime
            - name: zoneinfo
              readOnly: true
              mountPath: /usr/share/zoneinfo
          imagePullPolicy: IfNotPresent
      serviceAccount: event-exporter
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/controlplane
                    operator: In
                    values:
                      - 'true'
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/control-plane
                    operator: In
                    values:
                      - 'true'
            - weight: 100
              preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/master
                    operator: In
                    values:
                      - 'true'    
      tolerations:
        - key: node-role.kubernetes.io/controlplane
          value: 'true'
          effect: NoSchedule
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule
        - key: node-role.kubernetes.io/master
          operator: Exists
          effect: NoSchedule  

之后啟動 K3S 就會自動部署。

???Reference: 自動部署 manifests 和 Helm charts | Rancher 文檔

最終效果

如下圖:

???參考文檔

以上就是IoT邊緣集群Kubernetes Events告警通知實現(xiàn)示例的詳細內容,更多關于IoT集群Kubernetes Events告警的資料請關注腳本之家其它相關文章!

相關文章

  • 如何在kubernetes中創(chuàng)建Pod

    如何在kubernetes中創(chuàng)建Pod

    這篇文章主要介紹了如何在kubernetes中創(chuàng)建Pod,幫助大家更好的理解和學習使用kubernetes,感興趣的朋友可以了解下
    2021-04-04
  • centos7部署k8s集群1.28.2版本完整步驟

    centos7部署k8s集群1.28.2版本完整步驟

    部署Kubernetes集群需要多臺物理機或虛擬機,每個節(jié)點至少需要2個CPU、2GB內存和20GB硬盤空間,這篇文章主要給大家介紹了關于centos7部署k8s集群1.28.2版本的相關資料,需要的朋友可以參考下
    2024-01-01
  • k8s部署并測試ingress-nginx的詳細過程

    k8s部署并測試ingress-nginx的詳細過程

    這篇文章主要介紹了k8s部署并測試ingress-nginx的詳細過程,本文通過一個demo示例給大家介紹的非常詳細,感興趣的朋友一起看看吧
    2025-04-04
  • 在K8S中實現(xiàn)會話保持的兩種方案

    在K8S中實現(xiàn)會話保持的兩種方案

    這篇文章主要介紹了在K8S中實現(xiàn)會話保持的兩種方案,每種方案結合示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • 云原生技術kubernetes(K8S)簡介

    云原生技術kubernetes(K8S)簡介

    這篇文章主要介紹了云原生技術kubernetes的相關資料,幫助大家更好的理解和學習使用K8S,感興趣的朋友可以了解下
    2021-03-03
  • 基于云服務MRS構建DolphinScheduler2調度系統(tǒng)的案例詳解

    基于云服務MRS構建DolphinScheduler2調度系統(tǒng)的案例詳解

    這篇文章主要介紹了基于云服務MRS構建DolphinScheduler2調度系統(tǒng),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • k8s中的多網卡方案multus

    k8s中的多網卡方案multus

    這篇文章主要介紹了k8s中的多網卡方案multus,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 帶你學會k8s?更高級的對象Deployment

    帶你學會k8s?更高級的對象Deployment

    這篇文章主要為大家介紹了k8s還有更高級的"對象"Deployment使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04
  • k8s中pod不停重啟問題定位原因與解決方法

    k8s中pod不停重啟問題定位原因與解決方法

    這篇文章主要給大家介紹了關于k8s中pod不停重啟問題定位原因與解決方法的相關資料,Kubernetes是一款高度可擴展、可靠的容器編排和管理系統(tǒng),它簡化了容器的部署、管理和自動化操作,需要的朋友可以參考下
    2023-08-08
  • K8S命令如何查看日志

    K8S命令如何查看日志

    文章內容總結:K8S命令查看日志,列出所有節(jié)點、切換節(jié)點、查看容器日志及部分日志內容,個人經驗分享,希望對大家有所幫助
    2024-11-11

最新評論

灯塔市| 伊宁县| 蒙城县| 慈溪市| 宁化县| 康乐县| 五寨县| 莱州市| 唐河县| 海丰县| 遵化市| 芜湖县| 睢宁县| 象山县| 柏乡县| 青海省| 岱山县| 泰安市| 依安县| 平谷区| 泸水县| 盐亭县| 会同县| 贵溪市| 收藏| 陇南市| 柯坪县| 喜德县| 平陆县| 临夏市| 曲沃县| 寻甸| 叙永县| 泽库县| 香河县| 桂平市| 泰兴市| 广元市| 蓬安县| 垣曲县| 黔东|