臨時題目:查修 prometheus

因為工作滿滿,腦袋轉不動了,只能專心面對公司要務,原本要寫的題目先暫緩下。

狀況劇

我的環境監控,是透過Prometheus方案去進行的,最近經常因為 K8s node 異動,無意間也造成prometheus pod重新啟動,但帶來的問題是:先前的監控數據消失了。

原因與解法

prometheus pod本身沒有針對數據資料進行長久儲存動作~ 所以為此監控數據保存,我為prometheus pod新增了PVC、PV磁碟區,如此就能在prometheus pod重新啟動後,仍保有先前的監控數據。

使用 HELM 安裝\更新 Prometheus

指令說明

#安裝  stable/prometheus-operator
helm install --name prome stable/prometheus-operator -f ./prome-values.yaml

#更新  stable/prometheus-operator
helm upgrade prome stable/prometheus-operator -f ./prome-values.yaml

參數說明

# prome 所使用的參數檔案:  ./prome-values.yaml
# 異動前
prometheus:
  prometheusSpec:
    storageSpec: {}


# 異動後
prometheus:
  prometheusSpec:
    storageSpec: 
      volumeClaimTemplate:
        spec:
          storageClassName: standard
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 50Gi
        selector: {}

經過參數設定後,透過helm upgrade指令去更新 HELM Release name =prome,接著觀察pv、pvc使否正常創建與使用。

$ kubectl get pv,pvc
NAME                            CAPACITY  ACCESS MODES   RECLAIM POLICY   STATUS  CLAIM                   STORAGECLASS   REASON   AGE
persistentvolume/pvc-d316011d   50Gi      RWO            Delete           Bound   operator-prometheus-0   standard                34m

NAME                                          STATUS   VOLUME          CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/operator-prometheus-0   Bound    pvc-d316011d    50Gi       RWO            standard       34m

當然我也有故意重啟prometheus pod去驗證是否能保留監控數據。

Last updated