0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[OpenShift]Alertmanagerの設定

Posted at

はじめに

PrometheusのAlertmanagerを設定して、OpenShiftのアラートの設定方法を確認します。

バージョンはOCP4.5.4です。

$ oc version
Client Version: 4.5.4
Server Version: 4.5.4
Kubernetes Version: v1.18.3+012b3ec

Secretの設定

今回はアラートをメールで送信します。

Secretの確認とファイルへの書き出し

既存でできている alertmanager-main Secret を確認して、ファイルに書き出します。

$ oc describe secrets -n openshift-monitoring alertmanager-main
Name:         alertmanager-main
Namespace:    openshift-monitoring
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
alertmanager.yaml:  278 bytes

$ oc extract secret/alertmanager-main --to /tmp/ -n openshift-monitoring --confirm
/tmp/alertmanager.yaml

設定ファイルの編集

書き出した設定ファイルを以下のように編集します。

/tmp/alertmanager.yaml
"global":
  "resolve_timeout": "5m"
  smtp_smarthost: 192.168.1.254:24 #追記。 SMTPホスト
  smtp_from: alerts@example.com #追記。送信者のメールアドレス
  smtp_require_tls: false #追記。SMTPにTLSが必要かどうか
"receivers":
- "name": default #変更
- name: email-notification #追記。任意の名前
  email_configs: #追記。メールでアラートを送信する
  - to: hoge@example.com #追記。送信先メールアドレス
"route":
  "group_by":
  - "namespace"
  "group_interval": "5m"
  "group_wait": "30s"
  "receiver": default #変更
  "repeat_interval": 1m #変更。アラートを再送するまでの待機時間(すぐに再送されるように短くした)
  "routes":
  - "match":
      "alertname": "Watchdog"
    "receiver": default
  - match: #追記
      severity: warning #追記。Warningでアラートを送信する。(ここではすぐに送信されるようにWarningにした)
    receiver: email-notification #追記。使用するレシーバー

Secretの更新

編集したファイルでSecretを更新します。

$ oc set data secret/alertmanager-main -n openshift-monitoring --from-file /tmp/alertmanager.yaml
secret/alertmanager-main data updated

更新後、以下のログが出力されることを確認します。

$ oc logs -f -c alertmanager alertmanager-main-0 -n openshift-monitoring
・・・
level=info ts=2021-04-10T06:42:03.588Z caller=coordinator.go:131 component=configuration msg="Completed loading of configuration file" file=/etc/alertmanager/config/alertmanager.yaml

確認

アラートメールが送信されているか、クライアントで確認します。

$ mailx
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/lab": 2 messages 1 new
    1 alerts@example.  Fri Apr  9 09:48 188/10319 "[FIRING:1]  (AlertmanagerReceiversNotConfigured openshif"
>N  2 alerts@example.  Sat Apr 10 02:41 219/12401 "[FIRING:2]  (openshift-monitoring/k8s warning)"
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?