3.13. リモート書き込みストレージの設定
リモート書き込みストレージを設定して、Prometheus が取り込んだメトリクスをリモートシステムに送信して長期保存できるようにします。これを行っても、Prometheus がメトリクスを保存する方法や期間には影響はありません。
前提条件
OpenShift Container Platform のコアモニタリングコンポーネントを設定する場合、以下を実行します。
-
cluster-admin
クラスターロールを持つユーザーとしてクラスターにアクセスできる。 -
cluster-monitoring-config
ConfigMap
オブジェクトを作成している。
-
ユーザー定義のプロジェクトをモニターするコンポーネントを設定する場合:
-
cluster-admin
クラスターロールを持つユーザーとして、またはopenshift-user-workload-monitoring
プロジェクトのuser-workload-monitoring-config-edit
ロールを持つユーザーとして、クラスターにアクセスできる。 - クラスター管理者は、ユーザー定義プロジェクトのモニタリングを有効にしている。
-
-
OpenShift CLI (
oc
) がインストールされている。 リモート書き込み互換性のあるエンドポイント (Thanos) を設定し、エンドポイント URL を把握している。リモート書き込み機能と互換性のないエンドポイントの情報ては、Prometheus リモートエンドポイントおよびストレージに関するドキュメント を参照してください。
重要Red Hat は、リモート書き込み送信側の設定に関する情報のみを提供し、受信側エンドポイントの設定に関するガイダンスは提供しません。お客様は、リモート書き込みと互換性のある独自のエンドポイントを設定する責任があります。エンドポイントレシーバー設定に関する問題は、Red Hat 製品サポートには含まれません。
リモート書き込みエンドポイントの
Secret
オブジェクトに認証クレデンシャルを設定している。リモート書き込みを設定する Prometheus オブジェクトと同じ namespace にシークレットを作成する必要があります。デフォルトのプラットフォームモニタリングの場合はopenshift-monitoring
namespace、ユーザーのワークロードモニタリングの場合はopenshift-user-workload-monitoring
namespace です。警告セキュリティーリスクを軽減するには、HTTPS および認証を使用してメトリクスをエンドポイントに送信します。
手順
ConfigMap
オブジェクトを編集します。コア OpenShift Container Platform プロジェクトをモニターする Prometheus インスタンスのリモート書き込みを設定するには、次の手順を実行します。
openshift-monitoring
プロジェクトでcluster-monitoring-config
ConfigMap
オブジェクトを編集します。oc -n openshift-monitoring edit configmap cluster-monitoring-config
$ oc -n openshift-monitoring edit configmap cluster-monitoring-config
Copy to Clipboard Copied! 以下の例のように、
data/config.yaml/prometheusK8s
の下にremoteWrite:
セクションを追加します。apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials>
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com"
1 <endpoint_authentication_credentials>
2 Copy to Clipboard Copied! 認証クレデンシャルの後に、書き込みの再ラベル設定値を追加します。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> writeRelabelConfigs: - <your_write_relabel_configs>
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> writeRelabelConfigs: - <your_write_relabel_configs>
1 Copy to Clipboard Copied! - 1
- リモートエンドポイントに送信するメトリクスの設定を追加します。
my_metric
という単一メトリクスを転送する例apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__] regex: 'my_metric' action: keep
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__] regex: 'my_metric' action: keep
Copy to Clipboard Copied! my_namespace
namespace にmy_metric_1
およびmy_metric_2
というメトリクスを転送する例apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__,namespace] regex: '(my_metric_1|my_metric_2);my_namespace' action: keep
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__,namespace] regex: '(my_metric_1|my_metric_2);my_namespace' action: keep
Copy to Clipboard Copied!
ユーザー定義プロジェクトをモニターする Prometheus インスタンスのリモート書き込みを設定するには、次の手順を実行します。
openshift-user-workload-monitoring
プロジェクトでuser-workload-monitoring-config
ConfigMap
オブジェクトを編集します。oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config
$ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config
Copy to Clipboard Copied! 以下の例のように、
data/config.yaml/prometheus
の下にremoteWrite:
セクションを追加します。apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials>
apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com"
1 <endpoint_authentication_credentials>
2 Copy to Clipboard Copied! 認証クレデンシャルの後に、書き込みの再ラベル設定値を追加します。
apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> writeRelabelConfigs: - <your_write_relabel_configs>
apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> writeRelabelConfigs: - <your_write_relabel_configs>
1 Copy to Clipboard Copied! - 1
- リモートエンドポイントに送信するメトリクスの設定を追加します。
my_metric
という単一メトリクスを転送する例apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__] regex: 'my_metric' action: keep
apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__] regex: 'my_metric' action: keep
Copy to Clipboard Copied! my_namespace
namespace にmy_metric_1
およびmy_metric_2
というメトリクスを転送する例apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__,namespace] regex: '(my_metric_1|my_metric_2);my_namespace' action: keep
apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | prometheus: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: [__name__,namespace] regex: '(my_metric_1|my_metric_2);my_namespace' action: keep
Copy to Clipboard Copied!
- 変更を適用するためにファイルを保存します。新しい設定は自動的に適用されます。
3.13.1. サポート対象のリモート書き込み認証設定
異なる方法を使用して、リモート書き込みエンドポイントとの認証を行うことができます。現時点でサポートされている認証方法は AWS 署名バージョン 4、Basic 認証、認可、OAuth 2.0、および TLS クライアントです。以下の表は、リモート書き込みで使用するサポート対象の認証方法の詳細を示しています。
認証方法 | config map フィールド | 説明 |
---|---|---|
AWS 署名バージョン 4 |
| この方法では、AWS Signature Version 4 認証を使用して要求を署名します。この方法は、認可、OAuth 2.0、または Basic 認証と同時に使用することはできません。 |
Basic 認証 |
| Basic 認証は、設定されたユーザー名とパスワードを使用してすべてのリモート書き込み要求に承認ヘッダーを設定します。 |
認可 |
|
Authorization は、設定されたトークンを使用して、すべてのリモート書き込みリクエストに |
OAuth 2.0 |
|
OAuth 2.0 設定は、クライアントクレデンシャル付与タイプを使用します。Prometheus は、リモート書き込みエンドポイントにアクセスするために、指定されたクライアント ID およびクライアントシークレットを使用して |
TLS クライアント |
| TLS クライアント設定は、TLS を使用してリモート書き込みエンドポイントサーバーで認証するために使用される CA 証明書、クライアント証明書、およびクライアントキーファイル情報を指定します。設定例は、CA 証明書ファイル、クライアント証明書ファイル、およびクライアントキーファイルがすでに作成されていることを前提としています。 |
3.13.2. リモート書き込み認証の設定例
次のサンプルは、リモート書き込みエンドポイントに接続するために使用できるさまざまな認証設定を示しています。各サンプルでは、認証情報やその他の関連設定を含む対応する Secret
オブジェクトを設定する方法も示しています。それぞれのサンプルは、openshift-monitoring
namespace でデフォルトのプラットフォームモニタリングで使用する認証を設定します。
3.13.2.1. AWS 署名バージョン 4 認証のサンプル YAML
以下は、openshift-monitoring
namespace の sigv4-credentials
という名前の sigv 4
シークレットの設定を示しています。
apiVersion: v1 kind: Secret metadata: name: sigv4-credentials namespace: openshift-monitoring stringData: accessKey: <AWS_access_key> secretKey: <AWS_secret_key> type: Opaque
apiVersion: v1
kind: Secret
metadata:
name: sigv4-credentials
namespace: openshift-monitoring
stringData:
accessKey: <AWS_access_key>
secretKey: <AWS_secret_key>
type: Opaque
以下は、openshift-monitoring
namespace の sigv4-credentials
という名前の Secret
オブジェクトを使用する AWS Signature Version 4 リモート書き込み認証のサンプルを示しています。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://authorization.example.com/api/write" sigv4: region: <AWS_region> accessKey: name: sigv4-credentials key: accessKey secretKey: name: sigv4-credentials key: secretKey profile: <AWS_profile_name> roleArn: <AWS_role_arn>
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
prometheusK8s:
remoteWrite:
- url: "https://authorization.example.com/api/write"
sigv4:
region: <AWS_region>
accessKey:
name: sigv4-credentials
key: accessKey
secretKey:
name: sigv4-credentials
key: secretKey
profile: <AWS_profile_name>
roleArn: <AWS_role_arn>
3.13.2.2. 基本認証用のサンプル YAML
以下に、openshift-monitoring
namespace 内の rw-basic-auth
という名前の Secret
オブジェクトの基本認証設定のサンプルを示します。
apiVersion: v1 kind: Secret metadata: name: rw-basic-auth namespace: openshift-monitoring stringData: user: <basic_username> password: <basic_password> type: Opaque
apiVersion: v1
kind: Secret
metadata:
name: rw-basic-auth
namespace: openshift-monitoring
stringData:
user: <basic_username>
password: <basic_password>
type: Opaque
以下の例は、openshift-monitoring
namespace の rw-basic-auth
という名前の Secret
オブジェクトを使用する basicAuth
リモート書き込み設定を示しています。これは、エンドポイントの認証認証情報がすでに設定されていることを前提としています。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://basicauth.example.com/api/write" basicAuth: username: name: rw-basic-auth key: user password: name: rw-basic-auth key: password
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
prometheusK8s:
remoteWrite:
- url: "https://basicauth.example.com/api/write"
basicAuth:
username:
name: rw-basic-auth
key: user
password:
name: rw-basic-auth
key: password
3.13.2.3. Secret
オブジェクトを使用したベアラートークンによる認証のサンプル YAML
以下は、openshift-monitoring
namespace の rw-bearer-auth
という名前の Secret
オブジェクトのベアラートークン設定を示しています。
apiVersion: v1 kind: Secret metadata: name: rw-bearer-auth namespace: openshift-monitoring stringData: token: <authentication_token> type: Opaque
apiVersion: v1
kind: Secret
metadata:
name: rw-bearer-auth
namespace: openshift-monitoring
stringData:
token: <authentication_token>
type: Opaque
- 1
- 認証トークン。
以下は、openshift-monitoring
namespace の rw-bearer-auth
という名前の Secret
オブジェクトを使用するベアラートークン config map の設定例を示しています。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | enableUserWorkload: true prometheusK8s: remoteWrite: - url: "https://authorization.example.com/api/write" authorization: type: Bearer credentials: name: rw-bearer-auth key: token
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
enableUserWorkload: true
prometheusK8s:
remoteWrite:
- url: "https://authorization.example.com/api/write"
authorization:
type: Bearer
credentials:
name: rw-bearer-auth
key: token
3.13.2.4. OAuth 2.0 認証のサンプル YAML
以下は、openshift-monitoring
namespace の oauth2-credentials
という名前の Secret
オブジェクトの OAuth 2.0 設定のサンプルを示しています。
apiVersion: v1 kind: Secret metadata: name: oauth2-credentials namespace: openshift-monitoring stringData: id: <oauth2_id> secret: <oauth2_secret> type: Opaque
apiVersion: v1
kind: Secret
metadata:
name: oauth2-credentials
namespace: openshift-monitoring
stringData:
id: <oauth2_id>
secret: <oauth2_secret>
type: Opaque
以下は、openshift-monitoring
namespace の oauth2-credentials
という Secret
オブジェクトを使用した oauth2
リモート書き込み認証のサンプル設定です。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://test.example.com/api/write" oauth2: clientId: secret: name: oauth2-credentials key: id clientSecret: name: oauth2-credentials key: secret tokenUrl: https://example.com/oauth2/token scopes: - <scope_1> - <scope_2> endpointParams: param1: <parameter_1> param2: <parameter_2>
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
prometheusK8s:
remoteWrite:
- url: "https://test.example.com/api/write"
oauth2:
clientId:
secret:
name: oauth2-credentials
key: id
clientSecret:
name: oauth2-credentials
key: secret
tokenUrl: https://example.com/oauth2/token
scopes:
- <scope_1>
- <scope_2>
endpointParams:
param1: <parameter_1>
param2: <parameter_2>
- 1 3
- 対応する
Secret
オブジェクトの名前。ClientId
はConfigMap
オブジェクトを参照することもできますが、clientSecret
はSecret
オブジェクトを参照する必要があることに注意してください。 - 2 4
- 指定された
Secret
オブジェクトの OAuth 2.0 認証情報が含まれるキー。 - 5
- 指定された
clientId
およびclientSecret
でトークンを取得するために使用される URL。 - 6
- 認可要求の OAuth 2.0 スコープ。これらのスコープは、トークンがアクセスできるデータを制限します。
- 7
- 認可サーバーに必要な OAuth 2.0 認可要求パラメーター。
3.13.2.5. TLS クライアント認証のサンプル YAML
以下は、openshift-monitoring
namespace 内の mtls-bundle
という名前の tls
Secret
オブジェクトに対する TLS クライアント設定のサンプルです。
apiVersion: v1 kind: Secret metadata: name: mtls-bundle namespace: openshift-monitoring data: ca.crt: <ca_cert> client.crt: <client_cert> client.key: <client_key> type: tls
apiVersion: v1
kind: Secret
metadata:
name: mtls-bundle
namespace: openshift-monitoring
data:
ca.crt: <ca_cert>
client.crt: <client_cert>
client.key: <client_key>
type: tls
以下の例は、mtls-bundle
という名前の TLS Secret
オブジェクトを使用する tlsConfig
リモート書き込み認証設定を示しています。
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" tlsConfig: ca: secret: name: mtls-bundle key: ca.crt cert: secret: name: mtls-bundle key: client.crt keySecret: name: mtls-bundle key: client.key
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
prometheusK8s:
remoteWrite:
- url: "https://remote-write-endpoint.example.com"
tlsConfig:
ca:
secret:
name: mtls-bundle
key: ca.crt
cert:
secret:
name: mtls-bundle
key: client.crt
keySecret:
name: mtls-bundle
key: client.key
3.13.3. リモート書き込みキューの設定例
リモート書き込み用の queueConfig
オブジェクトを使用して、リモート書き込みキューパラメーターを調整できます。次の例は、openshift-monitoring
namespace のデフォルトプラットフォームモニタリングのキューパラメーターとそのデフォルト値を示しています。
デフォルト値を使用したリモート書き込みパラメーターの設定例
apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> queueConfig: capacity: 10000 minShards: 1 maxShards: 50 maxSamplesPerSend: 2000 batchSendDeadline: 5s minBackoff: 30ms maxBackoff: 5s retryOnRateLimit: false sampleAgeLimit: 0s
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
prometheusK8s:
remoteWrite:
- url: "https://remote-write-endpoint.example.com"
<endpoint_authentication_credentials>
queueConfig:
capacity: 10000
minShards: 1
maxShards: 50
maxSamplesPerSend: 2000
batchSendDeadline: 5s
minBackoff: 30ms
maxBackoff: 5s
retryOnRateLimit: false
sampleAgeLimit: 0s
- 1
- キューから削除される前にシャードごとにバッファーリングするサンプルの数。
- 2
- シャードの最小数。
- 3
- シャードの最大数
- 4
- 送信ごとの最大サンプル数。
- 5
- サンプルがバッファー内で待機する最大時間。
- 6
- 失敗したリクエストを再試行する前に待機する最初の時間。
maxbackoff
の時間になるまで、再試行するたびに時間が 2 倍になります。 - 7
- 失敗したリクエストを再試行するまでに待機する最大時間。
- 8
- リモート書き込みストレージから 429 ステータスコードを受信した後に要求を再試行するには、このパラメーターを
true
に設定します。 - 9
sampleAgeLimit
制限よりも古いサンプルはキューから削除されます。値が未定義であるか、0s
に設定されている場合、パラメーターは無視されます。