Istio

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

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

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

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

למידע נוסף על Istio, ראו Istio.

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

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

  • באשכול צריכה לפעול גרסה 1.28.15-gke.2475000 ומעלה של Google Kubernetes Engine.
  • צריך להפעיל את השירות המנוהל ל-Prometheus עם איסוף מנוהל. מידע נוסף זמין במאמר תחילת העבודה עם גבייה מנוהלת.

‫Istio חושף מדדים בפורמט Prometheus באופן אוטומטי, ואין צורך להתקין אותו בנפרד. כדי לוודא ש-Istio Proxy הוזרק כ-sidecar, ושגם Istiod (מישור הבקרה של Istio) וגם Istio Proxy פולטים מדדים בנקודות הקצה הצפויות, אתם יכולים להריץ את הבדיקות הבאות.

  • כדי לבדוק אם שרת ה-proxy של Istio מוזרק כ-sidecar, מריצים את הפקודה הבאה, שמפרטת את הקונטיינרים שפועלים ב-pods של האפליקציה:

    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.

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

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

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

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

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

אימות ההגדרות האישיות

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

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

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

    כניסה לדף Metrics Explorer

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

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

צפייה במרכזי הבקרה

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

כדי לראות מרכז בקרה שהותקן, מבצעים את הפעולות הבאות:

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

    עוברים אל מרכזי בקרה.

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

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

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

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

    עוברים אל שילובים.

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

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

פתרון בעיות

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