指标和 Service Mesh

使用指标

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

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

使用 Service Mesh 配置监控

您可以将 Alauda Service Mesh 与监控集成,以启用服务网格中的可观测性。监控可提供对关键内置工具的访问,并且是运行 Kiali(Istio 的专用控制台)的必需条件。

前提条件

  • 已安装 Alauda Service Mesh。

操作步骤

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

ServiceMonitor 对象示例

servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: istiod-monitor
  namespace: istio-system
  labels:
    # prometheus=kube-prometheus is required in ACP prometheus.
    prometheus: kube-prometheus
spec:
  targetLabels:
  - app
  selector:
    matchLabels:
      istio: pilot
  endpoints:
  - port: http-monitoring
    interval: 60s

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

kubectl apply -f servicemonitor.yaml

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

PodMonitor 对象示例

podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: istio-proxies-monitor
  namespace: istio-system
  labels:
    # prometheus=kube-prometheus is required in ACP prometheus.
    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}"
    # additional labels
    - sourceLabels: [__meta_kubernetes_namespace]
      action: replace
      targetLabel: namespace
    # - action: replace
    #   targetLabel: mesh_id
    #   replacement: "<mesh_id>"
  1. 指定必须在所有网格命名空间中应用 PodMonitor 对象,包括 Istio 控制平面命名空间,因为 Alauda Container Platform 监控会忽略 ServiceMonitorPodMonitor 对象中的 namespaceSelector 规范。
  2. 指定实际的网格 ID。只有在 ambient 模式下运行且多个集群共享同一个监控数据源时,才需要 mesh_id 标签。

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

kubectl apply -f podmonitor.yaml

创建名为 asm-telemetry.yaml 的 YAML 文件,用于为 Istio 代理(workloads)配置 prometheus 指标:

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: xds.node.metadata['MESH_ID']
  1. 为 prometheus 指标添加 mesh_id 标签。

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

kubectl apply -f asm-telemetry.yaml