Metrics and Service Mesh

目录

使用指标

应安装如 PrometheusVictoriaMetrics 等监控插件,为 Alauda Service Mesh v2 Operator 和 Istio 控制平面提供指标。

当您将应用添加到网格后,可以通过指标和自定义告警监控在 Alauda Container Platform 上运行的应用的集群内健康状况和性能,包括 CPU 和内存使用率、网络连接性及其他资源使用情况。

使用 Service Mesh 配置监控

您可以将 Alauda Service Mesh 与用户工作负载监控集成,以实现服务网格的可观测性。用户工作负载监控提供访问关键内置工具的能力,并且运行 Istio 专用控制台 Kiali 需要此监控。

前提条件

  • 已安装 Alauda Service Mesh。

操作步骤

创建名为 servicemonitor.yaml 的 YAML 文件,用于监控 Istio 控制平面:

示例 ServiceMonitor 对象

servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: istiod-monitor
  namespace: istio-system
spec:
  targetLabels:
  - app
  selector:
    matchLabels:
      istio: pilot
  endpoints:
  - port: http-monitoring
    interval: 60s

运行以下命令应用该 YAML 文件:

kubectl apply -f servicemonitor.yaml

创建名为 podmonitor.yaml 的 YAML 文件,用于收集 Istio 代理(工作负载)的指标:

示例 PodMonitor 对象

podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: istio-proxies-monitor
  namespace: istio-system
  labels:
    # monitoring=pods & prometheus=kube-prometheus 是 ACP prometheus 所必需的。
    monitoring: pods
    prometheus: kube-prometheus
spec:
  selector:
    matchExpressions:
    - key: istio-prometheus-ignore
      operator: DoesNotExist
  namespaceSelector:
    any: true
  jobLabel: envoy-stats
  podMetricsEndpoints:
  - path: /stats/prometheus
    interval: 60s
    relabelings:
    - action: keep
      sourceLabels: [ __meta_kubernetes_pod_container_name ]
      regex: "istio-proxy"
    - action: keep
      sourceLabels: [__meta_kubernetes_pod_annotationpresent_prometheus_io_scrape]
    - sourceLabels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
      action: replace
      regex: ([^:]+)(?::\d+)?;(\d+)
      replacement: "$1:$2"
      targetLabel: __address__
    - sourceLabels: [__meta_kubernetes_pod_label_app_kubernetes_io_name, __meta_kubernetes_pod_label_app]
      separator: ";"
      targetLabel: "app"
      action: replace
      regex: "(.+);.*|.*;(.+)"
      replacement: "${1}${2}"
    - sourceLabels: [__meta_kubernetes_pod_label_app_kubernetes_io_version, __meta_kubernetes_pod_label_version]
      separator: ";"
      targetLabel: "version"
      action: replace
      regex: "(.+);.*|.*;(.+)"
      replacement: "${1}${2}"
    - sourceLabels: [__meta_kubernetes_namespace]
      action: replace
      targetLabel: namespace
    - action: drop
      regex: "true"
      sourceLabels: [__meta_kubernetes_pod_container_init]
  1. 指定 PodMonitor 对象必须应用于所有网格命名空间,包括 Istio 控制平面命名空间,因为 Alauda Container Platform 监控会忽略 ServiceMonitorPodMonitor 对象中的 namespaceSelector 规范。

运行以下命令应用该 YAML 文件:

kubectl apply -f podmonitor.yaml

创建名为 asm-telemetry.yaml 的 YAML 文件,配置 prometheus 指标到 istio 代理(工作负载):

示例 Istio Telemetry 资源

asm-telemetry.yaml
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: asm-default
  namespace: istio-system
spec:
  metrics:
    - providers:
        - name: prometheus
      overrides:
        - tagOverrides:
            mesh_id:
              value: node.metadata['MESH_ID']
  1. 为 prometheus 指标添加 mesh_id 标签。

运行以下命令应用该 YAML 文件:

kubectl apply -f asm-telemetry.yaml