Istio

במאמר הזה מוסבר איך להגדיר את הפריסה של Google Kubernetes Engine כדי שתוכלו להשתמש בשירות המנוהל של Google Cloud ל-Prometheus כדי לאסוף מדדים מ-Istio. במאמר הזה מוסבר איך:

  • מגדירים את Istio לדיווח על מדדים.
  • אפשר לגשת למרכז בקרה מוגדר מראש ב-Cloud Monitoring כדי לראות את המדדים.
  • הגדרת כללי התראה למעקב אחר המדדים.

ההוראות האלה רלוונטיות רק אם אתם משתמשים ב אוסף מנוהל עם השירות המנוהל ל-Prometheus. אם אתם משתמשים באיסוף שמוטמע באופן עצמאי, תוכלו לעיין במאגר המקור של Istio כדי לקבל מידע על ההתקנה.

ההוראות האלה הן דוגמה, והן אמורות לפעול ברוב סביבות Kubernetes. אם נתקלתם בבעיה בהתקנת אפליקציה או כלי לייצוא בגלל מדיניות אבטחה או מדיניות ארגונית מגבילה, מומלץ לעיין במסמכי קוד פתוח לקבלת תמיכה.

מידע על Istio זמין במאמר Istio.

דרישות מוקדמות

כדי לאסוף מדדים מ-Istio באמצעות שירות מנוהל ל-Prometheus ואיסוף מנוהל, הפריסה צריכה לעמוד בדרישות הבאות:

  • האשכול צריך להריץ את Google Kubernetes Engine בגרסה ‎1.28.15-gke.2475000 ואילך.
  • צריך להפעיל את השירות המנוהל ל-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}'
    

    אם אתם רואים שה-pods מכילים את קונטיינר ה-sidecar‏ istio, סימן שהמייצא הוזרק. אם ה-sidecar לא מוזרק, צריך לפעול לפי ההוראות במאמר Istio: Installing the sidecar.

  • כדי לוודא שהמדדים מופקים על ידי Istio Proxy, מריצים את הפקודה הבאה, שבודקת את נקודת הקצה /stats/prometheus של istio בתרמיל שצוין:

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

    אם אתם רואים את המדדים הגולמיים istio_* ו-envoy_* של Prometheus, סימן שהמדדים מופקים בצורה תקינה.

  • כדי לוודא שהמדדים מופקים באופן דומה ב-Istiod, מריצים את הפקודה הבאה, שבודקת את נקודת הקצה /metrics של Istiod באחד מה-pods בפריסת istiod:

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

הגדרה של משאב PodMonitoring

כדי לגלות את היעד, ל-שירות מנוהל ל-Prometheus Operator נדרש משאב PodMonitoring שתואם ל-Istio באותו מרחב שמות.

אפשר להשתמש בהגדרה הבאה של 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 sidecars ושערי הכניסה והיציאה. כדי לעקוב אחרי מדדי Istio Proxy בכל מרחבי השמות באשכול בבת אחת, צריך להחיל את istio-proxy PodMonitoring על כל מרחב שמות או להגדיר משאב ClusterPodMonitoring במקום משאב PodMonitoring לכל מרחב שמות.

אם אתם מתכננים להשתמש בלוחות הבקרה של Grafana שסופקו על ידי Istio, בנוסף למשאבי PodMonitoring שמתוארים במסמך הזה, אתם צריכים לוודא שגם הגדרתם cAdvisor ו-Kubelet scraping.

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

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 מבוססת על כללי Istio שסופקו על ידי Awesome Prometheus Alerts. אפשר לשנות את ערכי הסף של ההתראות בהתאם לאפליקציה.

אימות ההגדרה

אתם יכולים להשתמש ב-Metrics Explorer כדי לוודא שהגדרתם את Istio בצורה נכונה. יכול להיות שיחלפו דקה או שתיים עד שמערכת Cloud Monitoring תעבד את המדדים.

כדי לוודא שהמדדים נאספים, מבצעים את הפעולות הבאות:

  1. במסוף Google Cloud , עוברים לדף  Metrics explorer:

    כניסה אל Metrics Explorer

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. בסרגל הכלים של חלונית הכלי ליצירת שאילתות, לוחצים על הלחצן ששמו הוא  MQL או  PromQL.
  3. מוודאים שהאפשרות PromQL נבחרה במתג שפה. המתג לשפה נמצא באותו סרגל כלים שבו אפשר לעצב את השאילתה.
  4. מזינים ומריצים את השאילתה הבאה:
    sum(istio_build{cluster="CLUSTER_NAME"}) by (component)
    

הצגת מרכזי בקרה

השילוב של Cloud Monitoring כולל את מרכז הבקרה Istio Envoy Prometheus Overview. לוחות הבקרה מותקנים באופן אוטומטי כשמגדירים את השילוב. אפשר גם לראות תצוגות מקדימות סטטיות של מרכזי בקרה בלי להתקין את האינטגרציה.

כדי לראות מרכז בקרה שהותקן:

  1. במסוף Google Cloud , עוברים לדף  Dashboards:

    מעבר אל מרכזי בקרה

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. לוחצים על הכרטיסייה רשימת מרכזי בקרה.
  3. בוחרים בקטגוריה שילובים.
  4. לוחצים על השם של מרכז הבקרה, למשל Istio Envoy Prometheus Overview.

כדי לראות תצוגה מקדימה סטטית של מרכז הבקרה:

  1. נכנסים לדף  Integrations במסוף Google Cloud :

    עוברים אל Integrations

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. לוחצים על המסנן Kubernetes Engine של פלטפורמת הפריסה.
  3. מאתרים את השילוב של Istio ולוחצים על הצגת פרטים.
  4. לוחצים על הכרטיסייה מרכזי בקרה.

פתרון בעיות

מידע על פתרון בעיות בהוספת מדדים זמין במאמר פתרון בעיות שקשורות להוספה, בקטע בעיות באיסוף נתונים ממייצאים.