Istio

本文件說明如何設定 Google Kubernetes Engine 部署作業,以便使用 Google Cloud Managed Service for Prometheus 收集 Istio 的指標。本文件說明如何執行下列操作:

  • 設定 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 Proxy 已以 sidecar 的形式插入,且 Istiod (Istio 的控制平面) 和 Istio Proxy 都會在預期的端點上發出指標。

  • 如要判斷 Istio Proxy 是否以附加元件形式插入,請執行下列指令,列舉應用程式 Pod 中執行的容器:

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

    如果您發現 Pod 包含 istio 側邊容器,表示匯出程式已插入。如果未注入側邊車,請按照 Istio:安裝側邊車中的操作說明進行。

  • 如要驗證 Istio Proxy 是否正在發出指標,請執行下列指令,這可檢查指定 Pod 上 istio/stats/prometheus 端點:

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

    如果您看到原始 istio_*envoy_* Prometheus 指標,表示系統已正確發出指標。

  • 如要確認指標是否在 Istiod 上以類似方式產生,請執行下列指令,檢查 istiod 部署中某個 Pod 的 Istiod /metrics 端點:

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

定義 PodMonitoring 資源

針對目標探索,Managed Service for Prometheus Operator 需要在相同命名空間中對應 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 需要兩個獨立的 PodMonitoring 資源:一個用於監控 Istiod,另一個用於監控 Istio Proxy 側邊車和入口和出口網關。如要同時監控叢集中所有命名空間的 Istio Proxy 指標,請將 istio-proxy PodMonitoring 套用至每個命名空間,或設定 ClusterPodMonitoring 資源,而非每個命名空間的 PodMonitoring 資源。

如果您打算使用 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. 前往 Google Cloud 控制台的 「Metrics Explorer」頁面:

    前往 Metrics Explorer

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果

  2. 在查詢建構工具窗格的工具列中,選取名稱為  MQL PromQL 的按鈕。
  3. 確認「Language」切換鈕中已選取「PromQL」。語言切換鈕位於可讓您設定查詢格式的工具列中。
  4. 輸入並執行以下查詢:
    sum(istio_build{cluster="CLUSTER_NAME"}) by (component)
    

查看資訊主頁

Cloud Monitoring 整合功能包含 Istio Envoy Prometheus 總覽資訊主頁。設定整合後,系統會自動安裝資訊主頁。您也可以不必安裝整合功能,直接查看資訊主頁的靜態預覽畫面。

如要查看已安裝的資訊主頁,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Dashboards」(資訊主頁) 頁面:

    前往「Dashboards」(資訊主頁)

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果

  2. 選取「資訊主頁清單」分頁標籤。
  3. 選擇「整合」類別。
  4. 按一下資訊主頁的名稱,例如 Istio Envoy Prometheus 總覽

如要查看資訊主頁的靜態預覽畫面,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Integrations」(整合) 頁面:

    前往「Integrations」

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果

  2. 按一下「Kubernetes Engine」部署平台篩選器。
  3. 找出 Istio 整合,然後按一下「查看詳細資料」
  4. 選取「資訊主頁」分頁標籤。

疑難排解

如要瞭解如何排解指標攝入問題,請參閱「 排解攝入端問題」一文中的「 從匯出工具收集資料時發生的問題」。