Istio

このドキュメントでは、Google Cloud Managed Service for Prometheus を使用して Istio から指標を収集できるように、Google Kubernetes Engine のデプロイを構成する方法について説明します。このドキュメントでは、次の方法について説明します。

  • 指標を報告するように Istio を設定します。
  • エクスポートされた指標を収集するために、Managed Service for Prometheus の PodMonitoring リソースを構成する。
  • Cloud Monitoring のダッシュボードにアクセスして指標を表示する。
  • 指標をモニタリングするようにアラートルールを構成する。

以下の手順は、Managed Service for Prometheus でマネージド コレクションを使用している場合にのみ適用されます。セルフデプロイ コレクションを使用している場合は、Istio のソース リポジトリでインストール情報をご覧ください。

以下の手順は一例であり、ほとんどの Kubernetes 環境で機能します。セキュリティ ポリシーや組織のポリシーの制限により、アプリケーションやエクスポータのインストールに問題がある場合は、オープンソース ドキュメントでサポートを確認することをおすすめします。

Istio については、Istio をご覧ください。

前提条件

Managed Service for Prometheus とマネージド コレクションを使用して Istio から指標を収集するには、デプロイが次の要件を満たしている必要があります。

  • クラスタで Google Kubernetes Engine バージョン 1.21.4-gke.300 以降を実行している必要があります。
  • マネージド コレクションを有効にして、Managed Service for Prometheus を実行する必要があります。詳細については、マネージド コレクションを使ってみるをご覧ください。

Istio は、Prometheus 形式の指標を自動的に公開します。別途インストールする必要はありません。次のチェックを実行して、Istio プロキシがサイドカーとして挿入され、Istio のコントロール プレーンである Istiod と Istio Proxy の両方が想定したエンドポイントで指標を出力していることを確認します。

  • Istio プロキシがサイドカーとして挿入されているかどうかを判別するには、次のコマンドを実行します。これにより、アプリケーションの Pod で実行されているコンテナが列挙されます。

    kubectl get pod -l app=APPLICATION_NAME -n NAMESPACE_NAME -o jsonpath='{.items[0].spec.containers[*].name}'
    

    Pod に istio サイドカー コンテナが含まれていることを確認できた場合、エクスポータが挿入されています。サイドカーが挿入されていない場合は、Istio のサイドカーのインストールの手順を完了してください。

  • Istio プロキシによって指標が出力されていることを確認するには、次のコマンドを実行します。これにより、指定した Pod の istio/stats/prometheus エンドポイントが検査されます。

    kubectl exec POD_NAME -n NAMESPACE_NAME -c istio-proxy -- curl -sS 'localhost:15090/stats/prometheus'
    

    Prometheus の istio_* 指標と envoy_* 指標が表示されている場合、指標は正しく出力されています。

  • Istiod で指標が同様に出力されていることを確認するには、次のコマンドを実行します。これにより、istiod Deployment の Pod の 1 つで Istio の /metrics エンドポイントが検査されます。

    kubectl exec -n istio-system deployment/istiod -- curl -sS 'localhost:15014/metrics'
    

PodMonitoring リソースを定義する

ターゲット ディスカバリの場合、Managed Service for Prometheus Operator には、同じ Namespace 内の Istio エクスポータに対応する PodMonitoring リソースが必要です。

次の PodMonitoring 構成を使用できます。

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: istiod
  namespace: istio-system
  labels:
    app.kubernetes.io/name: istiod
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  selector:
    matchLabels:
      app: istiod
  endpoints:
  - port: 15014
    interval: 30s
    path: /metrics
  targetLabels:
    fromPod:
    - from: app
      to: app
---
apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: istio-proxy
  labels:
    app.kubernetes.io/name: istio-proxy
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  selector:
    matchLabels:
  endpoints:
  - port: http-envoy-prom
    scheme: http
    interval: 30s
    path: /stats/prometheus
Istio には、2 つの別個の PodMonitoring リソースが必要です。1 つは Istiod をモニタリングするリソースです。もう 1 つは、Istio プロキシ サイドカー、Ingress ゲートウェイおよび Egress ゲートウェイをモニタリングするリソースです。クラスタ内のすべての Namespace で Istio プロキシ指標を一度にモニタリングするには、istio-proxy PodMonitoring をすべての Namespace に適用するか、Namespace ごとの PodMonitoring リソースの代わりに ClusterPodMonitoring リソースを設定します。

Istio 提供の Grafana ダッシュボードを使用する場合は、このドキュメントで説明する PodMonitoring リソースに加えて、cAdvisor と kubelet のスクレイピングを構成しておく必要があります。

構成の変更内容をローカル ファイルから適用するには、次のコマンドを実行します。

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform を使用して構成を管理することもできます。

ルールとアラートを定義する

次の Rules 構成を使用して、Istio 指標に関するアラートを定義します。

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: Rules
metadata:
  name: istio-rules
  labels:
    app.kubernetes.io/component: rules
    app.kubernetes.io/name: istio-rules
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  groups:
  - name: istio
    interval: 30s
    rules:
    - alert: IstioHighTotalRequestRate
      expr: sum(rate(istio_requests_total{reporter="destination"}[5m])) > 1000
      for: 2m
      labels:
        severity: warning
      annotations:
        summary: Istio high total request rate (instance {{ $labels.instance }})
        description: |-
          Global request rate in the service mesh is unusually high.
            VALUE = {{ $value }}
            LABELS = {{ $labels }}
    - alert: IstioLowTotalRequestRate
      expr: sum(rate(istio_requests_total{reporter="destination"}[5m])) < 100
      for: 2m
      labels:
        severity: warning
      annotations:
        summary: Istio low total request rate (instance {{ $labels.instance }})
        description: |-
          Global request rate in the service mesh is unusually low.
            VALUE = {{ $value }}
            LABELS = {{ $labels }}
    - alert: IstioHigh4xxErrorRate
      expr: sum(rate(istio_requests_total{reporter="destination", response_code=~"4.*"}[5m])) / sum(rate(istio_requests_total{reporter="destination"}[5m])) * 100 > 5
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: Istio high 4xx error rate (instance {{ $labels.instance }})
        description: |-
          High percentage of HTTP 5xx responses in Istio (> 5%).
            VALUE = {{ $value }}
            LABELS = {{ $labels }}
    - alert: IstioHigh5xxErrorRate
      expr: sum(rate(istio_requests_total{reporter="destination", response_code=~"5.*"}[5m])) / sum(rate(istio_requests_total{reporter="destination"}[5m])) * 100 > 5
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: Istio high 5xx error rate (instance {{ $labels.instance }})
        description: |-
          High percentage of HTTP 5xx responses in Istio (> 5%).
            VALUE = {{ $value }}
            LABELS = {{ $labels }}
    - alert: IstioHighRequestLatency
      expr: rate(istio_request_duration_milliseconds_sum{reporter="destination"}[1m]) / rate(istio_request_duration_milliseconds_count{reporter="destination"}[1m]) > 100
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: Istio high request latency (instance {{ $labels.instance }})
        description: |-
          Istio average requests execution is longer than 100ms.
            VALUE = {{ $value }}
            LABELS = {{ $labels }}
    - alert: IstioLatency99Percentile
      expr: histogram_quantile(0.99, sum(rate(istio_request_duration_milliseconds_bucket[1m])) by (destination_canonical_service, destination_workload_namespace, source_canonical_service, source_workload_namespace, le)) > 1
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: Istio latency 99 percentile (instance {{ $labels.instance }})
        description: |-
          Istio 1% slowest requests are longer than 1s.
            VALUE = {{ $value }}
            LABELS = {{ $labels }}

構成の変更内容をローカル ファイルから適用するには、次のコマンドを実行します。

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform を使用して構成を管理することもできます。

ルールをクラスタに適用する方法については、マネージド ルールの評価とアラートをご覧ください。

この Rules 構成は、Awesome Prometheus アラートによって提供される Istio ルールを元にしています。アラートのしきい値は、アプリケーションに合わせて調整できます。

構成を確認する

Metrics Explorer を使用すると、Istio エクスポータが正しく構成されていることを確認できます。Cloud Monitoring が指標を取り込むまでに 1~2 分かかる場合があります。

指標が取り込まれていることを確認する手順は次のとおりです。

  1. Google Cloud コンソールのナビゲーション パネルで [Monitoring] を選択し、次に [ Metrics Explorer] を選択します。

    Metrics Explorer に移動

  2. クエリビルダー ペインのツールバーで、[MQL] または [PROMQL] という名前のボタンを選択します。
  3. [言語] で [PromQL] が選択されていることを確認します。言語切り替えボタンは、クエリの書式設定と同じツールバーにあります。
  4. 次のクエリを入力して実行します。
    sum(istio_build{cluster="CLUSTER_NAME"}) by (component)
    

ダッシュボードを表示する

Cloud Monitoring インテグレーションには、Istio Envoy Prometheus の概要ダッシュボードが含まれています。ダッシュボードは、インテグレーションを構成すると自動的にインストールされます。インテグレーションをインストールすることなく、ダッシュボードの静的プレビューを表示することもできます。

インストールされているダッシュボードを表示する手順は次のとおりです。

  1. Google Cloud コンソールのナビゲーション パネルで、[Monitoring] を選択してから、[ダッシュボード] を選択します。

    [ダッシュボード] に移動

  2. [ダッシュボード リスト] タブを選択します。
  3. [統合] カテゴリを選択します。
  4. ダッシュボードの名前(たとえば、Istio Envoy Prometheus Overview)をクリックします。

ダッシュボードの静的プレビューを表示する手順は次のとおりです。

  1. Google Cloud コンソールのナビゲーション パネルで、[Monitoring] を選択してから、[インテグレーション] を選択します。

    [インテグレーション] に移動

  2. [デプロイメント プラットフォーム] フィルタの [Kubernetes Engine] をクリックします。
  3. Istio インテグレーションを見つけ、[詳細を表示] をクリックします。
  4. [ダッシュボード] タブを選択します。

トラブルシューティング

指標の取り込みに関する問題のトラブルシューティングについては、取り込み側の問題のトラブルシューティングエクスポータからの収集に関する問題をご覧ください。