2.17.8. ユーザーのワークロード監視との統合
デフォルトでは、Red Hat OpenShift Service Mesh (OSSM) は、メッシュからメトリクスを収集するための Prometheus の専用インスタンスを含む Service Mesh コントロールプレーン (SMCP) をインストールします。ただし、実稼働システムには、ユーザー定義プロジェクトの OpenShift Container Platform モニタリングなど、より高度なモニタリングシステムが必要です。
次の手順では、Service Mesh をユーザーワークロードの監視と統合する方法を示します。
前提条件
- ユーザーのワークロードの監視が有効になっている。
- Red Hat OpenShift Service Mesh Operator 2.4 がインストールされている。
- Kiali Operator 1.65 がインストールされている。
手順
cluster-monitoring-viewロールを Kiali サービスアカウントに付与します。apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: kiali-monitoring-rbac roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-monitoring-view subjects: - kind: ServiceAccount name: kiali-service-account namespace: istio-systemユーザーワークロードを監視するために Kiali を設定します。
apiVersion: kiali.io/v1alpha1 kind: Kiali metadata: name: kiali-user-workload-monitoring namespace: istio-system spec: external_services: prometheus: auth: type: bearer use_kiali_token: true query_scope: mesh_id: "basic-istio-system" thanos_proxy: enabled: true url: https://thanos-querier.openshift-monitoring.svc.cluster.local:9091Istio Operator 2.4 を使用する場合は、次の設定を使用して Kiali をユーザーワークロードモニタリング用に設定します。
apiVersion: kiali.io/v1alpha1 kind: Kiali metadata: name: kiali-user-workload-monitoring namespace: istio-system spec: external_services: istio: config_map_name: istio-<smcp-name> istio_sidecar_injector_config_map_name: istio-sidecar-injector-<smcp-name> istiod_deployment_name: istiod-<smcp-name> url_service_version: 'http://istiod-<smcp-name>.istio-system:15014/version' prometheus: auth: token: secret:thanos-querier-web-token:token type: bearer use_kiali_token: false query_scope: mesh_id: "basic-istio-system" thanos_proxy: enabled: true url: https://thanos-querier.openshift-monitoring.svc.cluster.local:9091 version: v1.65
外部 Prometheus 用に SMCP を設定します。
apiVersion: maistra.io/v2 kind: ServiceMeshControlPlane metadata: name: basic namespace: istio-system spec: addons: prometheus: enabled: false1 grafana: enabled: false2 kiali: name: kiali-user-workload-monitoring meshConfig: extensionProviders: - name: prometheus prometheus: {}カスタムネットワークポリシーを適用して、モニタリング namespace からの受信トラフィックを許可します。
apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: user-workload-access namespace: istio-system1 spec: ingress: - from: - namespaceSelector: matchLabels: network.openshift.io/policy-group: monitoring podSelector: {} policyTypes: - Ingress- 1
- カスタムネットワークポリシーはすべての namespace に適用する必要があります。
Telemetryオブジェクトを適用して、Istio プロキシーのトラフィックメトリクスを有効にします。apiVersion: telemetry.istio.io/v1alpha1 kind: Telemetry metadata: name: enable-prometheus-metrics namespace: istio-system1 spec: selector:2 matchLabels: app: bookinfo metrics: - providers: - name: prometheusServiceMonitorオブジェクトを適用して Istio コントロールプレーンを監視します。apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: istiod-monitor namespace: istio-system1 spec: targetLabels: - app selector: matchLabels: istio: pilot endpoints: - port: http-monitoring interval: 30s relabelings: - action: replace replacement: "basic-istio-system"2 targetLabel: mesh_id- 1
- この
ServiceMonitorオブジェクトは Istiod サービスを監視するため、Istio コントロールプレーン namespace に作成します。この例では、namespace はistio-systemです。 - 2
- 文字列
"basic-istio-system"は、SMCP 名とその namespace の組み合わせですが、クラスター内のユーザーワークロード監視を使用するメッシュごとに一意である限り、任意のラベルを使用できます。ステップ 2 で設定した Kiali リソースのspec.prometheus.query_scopeは、この値と一致する必要があります。注記ユーザーワークロードモニタリングを使用しているメッシュが 1 つだけの場合は、Kiali リソースの
mesh_idの再ラベル付けとspec.prometheus.query_scopeフィールドは、両方とも任意です (ただし、mesh_idラベルが削除された場合は、ここで指定したquery_scopeフィールドも削除する必要があります)。クラスター上の複数のメッシュインスタンスがユーザーワークロードのモニタリングを使用する可能性がある場合は、Kiali リソースの
mesh_idの再ラベル付けとspec.prometheus.query_scopeフィールドの両方が必要です。これにより、Kiali は関連付けられたメッシュからのメトリクスのみ参照します。Kiali をデプロイしていない場合でも、別のメッシュのメトリクスを区別できるように
mesh_idの再ラベル付けを適用できます。
PodMonitorオブジェクトを適用して、Istio プロキシーからメトリクスを収集します。apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: name: istio-proxies-monitor namespace: istio-system1 spec: selector: matchExpressions: - key: istio-prometheus-ignore operator: DoesNotExist podMetricsEndpoints: - path: /stats/prometheus interval: 30s relabelings: - action: keep sourceLabels: [__meta_kubernetes_pod_container_name] regex: "istio-proxy" - action: keep sourceLabels: [__meta_kubernetes_pod_annotationpresent_prometheus_io_scrape] - action: replace regex: (\d+);(([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}) replacement: '[$2]:$1' sourceLabels: [__meta_kubernetes_pod_annotation_prometheus_io_port, __meta_kubernetes_pod_ip] targetLabel: __address__ - action: replace regex: (\d+);((([0-9]+?)(\.|$)){4}) replacement: $2:$1 sourceLabels: [__meta_kubernetes_pod_annotation_prometheus_io_port, __meta_kubernetes_pod_ip] targetLabel: __address__ - action: labeldrop regex: "__meta_kubernetes_pod_label_(.+)" - sourceLabels: [__meta_kubernetes_namespace] action: replace targetLabel: namespace - sourceLabels: [__meta_kubernetes_pod_name] action: replace targetLabel: pod_name - action: replace replacement: "basic-istio-system"2 targetLabel: mesh_id- 1
- OpenShift Container Platform モニタリングは
ServiceMonitorオブジェクトとPodMonitorオブジェクトのnamespaceSelector仕様を無視するため、コントロールプレーンの namespace を含むすべてのメッシュ namespace にPodMonitorオブジェクトを適用する必要があります。 - 2
- 文字列
"basic-istio-system"は、SMCP 名とその namespace の組み合わせですが、クラスター内のユーザーワークロード監視を使用するメッシュごとに一意である限り、任意のラベルを使用できます。ステップ 2 で設定した Kiali リソースのspec.prometheus.query_scopeは、この値と一致する必要があります。注記ユーザーワークロードモニタリングを使用しているメッシュが 1 つだけの場合は、Kiali リソースの
mesh_idの再ラベル付けとspec.prometheus.query_scopeフィールドは、両方とも任意です (ただし、mesh_idラベルが削除された場合は、ここで指定したquery_scopeフィールドも削除する必要があります)。クラスター上の複数のメッシュインスタンスがユーザーワークロードのモニタリングを使用する可能性がある場合は、Kiali リソースの
mesh_idの再ラベル付けとspec.prometheus.query_scopeフィールドの両方が必要です。これにより、Kiali は関連付けられたメッシュからのメトリクスのみ参照します。Kiali をデプロイしていない場合でも、別のメッシュのメトリクスを区別できるように
mesh_idの再ラベル付けを適用できます。
- OpenShift Container Platform Web コンソールを開き、メトリクスが表示されていることを確認します。