LoginSignup
5
6

OpenShift Prometheusで設定変更しておいた方がよいこと

Last updated at Posted at 2024-04-05

これら設定変更をするとprometheus-k8s podの再起動が発生し、それまで保管されていたPrometheusのデータが失われますのでご注意ください。
検証環境:OCP 4.12

データ保持期間

Prometheusのデータ保持期間はデフォルトで15日になっています。これを適切な保持期間に変更します。

# oc get pod -o yaml prometheus-k8s-0 -n openshift-monitoring | grep retention
    - --storage.tsdb.retention.time=15d

OpenShiftのモニタリングスタックの設定変更は、cluster-monitoring-config ConfigMapで行います。
この環境では、cluster-monitoring-config ConfigMap オブジェクトが存在しませんでした。(デフォルトの状態では存在しないようです。)

# oc -n openshift-monitoring get configmap cluster-monitoring-config
Error from server (NotFound): configmaps "cluster-monitoring-config" not found

1. cluster-monitoring-config ConfigMapを作成します。

参考:クラスターモニタリング設定マップの作成

# vi cluster-monitoring-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: cluster-monitoring-config
  namespace: openshift-monitoring
data:
  config.yaml: |

# oc apply -f cluster-monitoring-config.yaml
configmap/cluster-monitoring-config created

2. cluster-monitoring-config ConfigMapに保持期間retentionを設定します。

参考:2.4. モニタリングスタックの設定

# oc -n openshift-monitoring edit configmap cluster-monitoring-config

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  config.yaml: |
    prometheusK8s:
      retention: "30d"
kind: ConfigMap

prometheus-k8s-0prometheus-k8s-1 podが自動的に再起動し、保持期間が30日に変更されました。

# oc get pods -n openshift-monitoring
NAME                                                     READY   STATUS    RESTARTS      AGE
alertmanager-main-0                                      6/6     Running   0             26d
alertmanager-main-1                                      6/6     Running   1 (26d ago)   26d
cluster-monitoring-operator-58db5c8b4b-c5nnf             2/2     Running   0             32d
kube-state-metrics-6ff9b587f-vcwfz                       3/3     Running   0             26d
node-exporter-2hff2                                      2/2     Running   4             32d
node-exporter-44m8c                                      2/2     Running   4             32d
node-exporter-58pl6                                      2/2     Running   0             31d
node-exporter-7chmr                                      2/2     Running   2             32d
node-exporter-8bs82                                      2/2     Running   6             32d
node-exporter-dxqhx                                      2/2     Running   0             32d
node-exporter-jms4s                                      2/2     Running   2             32d
node-exporter-knx58                                      2/2     Running   0             32d
node-exporter-szzhw                                      2/2     Running   2             32d
node-exporter-vpvqj                                      2/2     Running   2             32d
openshift-state-metrics-7fd65c7d8c-p9qhk                 3/3     Running   0             26d
prometheus-adapter-84888f6967-5bcrd                      1/1     Running   0             88m
prometheus-adapter-84888f6967-vfvlx                      1/1     Running   0             88m
prometheus-k8s-0                                         6/6     Running   0             2m3s
prometheus-k8s-1                                         6/6     Running   0             2m22s
prometheus-operator-6ddd5d5d64-8cf54                     2/2     Running   0             31d
prometheus-operator-admission-webhook-5fbbd94549-8l6rw   1/1     Running   0             26d
prometheus-operator-admission-webhook-5fbbd94549-q262r   1/1     Running   0             26d
telemeter-client-6544d48db-2m6xv                         3/3     Running   0             26d
thanos-querier-6fb4df84f6-9rhbv                          6/6     Running   0             26d
thanos-querier-6fb4df84f6-xtk5h                          6/6     Running   0             26d

# oc get pod -o yaml prometheus-k8s-0 -n openshift-monitoring| grep retention
    - --storage.tsdb.retention.time=30d

参考

データ書き込み先(保管場所)の変更

デフォルトではemptyDirに書き込まれることになっているため、Podが停止した場合データが失われます。データを保持できるよう、書き込み先を永続ボリュームに変更します。

データ保持期間と同じく、cluster-monitoring-config ConfigMapで設定します。

以下の設定例は、storageClass ocs-storagecluster-ceph-rbd に40Giの永続ボリュームを要求する PVC を設定する例です。(retention: "30d"の下6行です。)

# oc edit configmap cluster-monitoring-config -n openshift-monitoring
 :
apiVersion: v1
data:
  config.yaml: |
    prometheusK8s:
      retention: "30d"
      volumeClaimTemplate:
        spec:
          storageClassName: ocs-storagecluster-ceph-rbd
          resources:
            requests:
              storage: 40Gi
kind: ConfigMap
 :

この場合も、prometheus-k8s-0prometheus-k8s-1 podが自動的に再起動し、データ保管先となるPVCが付与されデータ書き込み先が変更されました。

# oc describe pod prometheus-k8s-0 -n openshift-monitoring
 :
Volumes:
  prometheus-k8s-db:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  prometheus-k8s-db-prometheus-k8s-0
    ReadOnly:   false
 :


# oc get pvc -n openshift-monitoring
NAME                                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                  AGE
prometheus-k8s-db-prometheus-k8s-0   Bound    pvc-1519fbaf-a33a-4f2f-9ac2-71c2e20e9272   40Gi       RWO            ocs-storagecluster-ceph-rbd   38m
prometheus-k8s-db-prometheus-k8s-1   Bound    pvc-29dddf3a-d86c-45b8-86d0-961e2ecf9446   40Gi       RWO            ocs-storagecluster-ceph-rbd   38m

参考

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6