2.11. リモート書き込みストレージの設定
リモート書き込みストレージを設定して、Prometheus が取り込んだメトリックをリモートシステムに送信して長期保存できるようにします。これを行っても、Prometheus がメトリックを保存する方法や期間には影響はありません。
前提条件
OpenShift Container Platform のコアモニタリングコンポーネントを設定する場合、以下を実行します。
-
cluster-adminクラスターロールを持つユーザーとしてクラスターにアクセスできます。 -
cluster-monitoring-configConfigMapオブジェクトを作成している。
-
ユーザー定義のプロジェクトをモニターするコンポーネントを設定する場合:
-
cluster-adminクラスターロールを持つユーザーとして、またはopenshift-user-workload-monitoringプロジェクトのuser-workload-monitoring-config-editロールを持つユーザーとして、クラスターにアクセスできる。 -
user-workload-monitoring-configConfigMapオブジェクトを作成している。
-
-
OpenShift CLI (
oc) がインストールされている。 - リモート書き込み互換性のあるエンドポイント (Thanos) を設定し、エンドポイント URL を把握している。リモート書き込み機能と互換性のないエンドポイントの情報ては、Prometheus リモートエンドポイントおよびストレージについてのドキュメント を参照してください。
リモート書き込みエンドポイントの
Secretオブジェクトに認証クレデンシャルを設定している。リモート書き込みを設定する Prometheus オブジェクトと同じ namespace にシークレットを作成する必要があります。デフォルトのプラットフォームモニタリングの場合はopenshift-monitoringnamespace 、ユーザーのワークロードモニタリングの場合はopenshift-user-workload-monitoringnamespace です。Importantセキュリティーリスクを軽減するには、HTTPS および認証を使用してメトリックをエンドポイントに送信します。
手順
以下の手順に従って、openshift-monitoring namespace の cluster-monitoring-config config マップで、デフォルトのプラットフォーム監視のリモート書き込みを設定します。
ユーザー定義プロジェクトをモニターする Prometheus インスタンスのリモート書き込みを設定する場合は、openshift-user-workload-monitoring namespace の user-workload-monitoring-config 設定マップと同様の編集を行います。なお、Prometheus のコンフィグマップコンポーネントは、user-workload-monitoring-configConfigMap オブジェクトでは prometheus と呼ばれ、prometheusK8s ではないことに注意してください。これは、cluster-monitoring-configConfigMap オブジェクトにあるためです。
openshift-monitoringプロジェクトでcluster-monitoring-configConfigMapオブジェクトを編集します。$ oc -n openshift-monitoring edit configmap cluster-monitoring-config-
data/config.yaml/prometheusK8sにremoteWrite:セクションを追加します。 このセクションにエンドポイント URL および認証情報を追加します。
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 認証クレデンシャルの後に、書き込みの再ラベル設定値を追加します。
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> <write_relabel_configs>1 - 1
- 書き込みの再ラベル設定。
<write_relabel_configs>は、リモートエンドポイントに送信する必要のあるメトリクスの書き込みラベル一覧に置き換えます。以下の例では、
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書き込み再ラベル設定オプションについては、Prometheus relabel_config documentation を参照してください。
ファイルを保存して、変更を
ConfigMapオブジェクトに適用します。新規設定の影響を受けた Pod は自動的に再起動します。注記user-workload-monitoring-configConfigMapオブジェクトに適用される設定は、クラスター管理者がユーザー定義プロジェクトのモニタリングを有効にしない限りアクティブにされません。警告モニタリング
ConfigMapオブジェクトへの変更を保存すると、関連するプロジェクトの Pod およびその他のリソースが再デプロイされる可能性があります。また、変更を保存すると、そのプロジェクトで実行中のモニタリングプロセスも再起動する可能性があります。
2.11.1. サポート対象のリモート書き込み認証設定 リンクのコピーリンクがクリップボードにコピーされました!
異なる方法を使用して、リモート書き込みエンドポイントとの認証を行うことができます。現在サポートされている認証方法は、AWS 署名バージョン 4、基本認証、Authorization リクエストヘッダーでの HTTP を使用した認証、OAuth 2.0、および TLS クライアントです。以下の表は、リモート書き込みで使用するサポート対象の認証方法の詳細を示しています。
| 認証方法 | 設定マップフィールド | 説明 |
|---|---|---|
| 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 証明書ファイル、クライアント証明書ファイル、およびクライアントキーファイルがすでに作成されていることを前提としています。 |
2.11.1.1. 認証設定の設定マップの場所 リンクのコピーリンクがクリップボードにコピーされました!
以下は、デフォルトのプラットフォームモニタリングの ConfigMap オブジェクトの認証設定の場所を示しています。
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_details>
ユーザー定義プロジェクトを監視する Prometheus インスタンスに対してリモート書き込みを設定する場合は、openshift-user-workload-monitoring namespace の user-workload-monitoring-config を編集してください。なお、Prometheus のコンフィグマップコンポーネントは、user-workload-monitoring-configConfigMap オブジェクトでは prometheus と呼ばれ、prometheusK8s ではないことに注意してください。これは、cluster-monitoring-configConfigMap オブジェクトにあるためです。
2.11.1.2. リモート書き込み認証の設定例 リンクのコピーリンクがクリップボードにコピーされました!
次のサンプルは、リモート書き込みエンドポイントに接続するために使用できるさまざまな認証設定を示しています。各サンプルでは、認証情報やその他の関連設定を含む対応する Secret オブジェクトを設定する方法も示しています。それぞれのサンプルは、openshift-monitoring namespace でデフォルトのプラットフォームモニタリングで使用する認証を設定します。
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
以下は、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>
基本認証用のサンプル 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
以下の例は、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
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
- 1
- 認証トークン。
以下は、openshift-monitoring namespace の rw-bearer-auth という名前の Secret オブジェクトを使用するベアラートークン設定マップの設定例を示しています。
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
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>
token: <oauth2_authentication_token>
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>
- 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 認可要求パラメーター。
TLS クライアント認証のサンプル YAML
以下は、openshift-monitoring namespace 内の mtls-bundle という名前の tlsSecret オブジェクトに対する 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