服务网格ASM的Mixerless Telemetry技术,为业务容器提供了无侵入式的遥测数据。遥测数据作为监控指标被ARMS Prometheus或Prometheus采集,实现服务网格可观测性。本文以Prometheus为例,介绍如何基于ASM采集应用监控指标实现服务网格的可观测性。

前提条件

步骤一:安装Prometheus

  1. 下载Istio安装包,并解压。关于Istio安装包下载地址,请参见Download Istio
  2. 通过kubectl连接集群。具体操作,请参见获取集群KubeConfig并通过kubectl工具连接集群
  3. 执行以下命令,安装Prometheus。
    kubectl --kubeconfig <kubeconfig位置> apply -f <解压后Istio安装包位置>/samples/addons/prometheus.yaml

步骤二:创建集群外服务(ServiceEntry)

  1. 登录ASM控制台
  2. 在左侧导航栏,选择服务网格 > 网格管理
  3. 网格管理页面,找到待配置的实例,单击实例的名称或在操作列中单击管理
  4. 在网格详情页面左侧导航栏,选择网格实例 > 基本信息,然后在右侧页面,单击功能设置
  5. 功能设置更新面板选中开启采集Prometheus监控指标,选择启用已有Prometheus,在文本框中输入Prometheus服务地址,本文使用默认服务地址http://prometheus:9090,然后单击确定
    说明 本文已自建Prometheus为例,如果您使用的是ARMS Prometheus,请参见集成ARMS Prometheus实现网格监控
    在网格详情页面左侧导航栏选择集群与工作负载管理 > 集群外服务(ServiceEntry),可以看到生成的相关EnvoyFilter。

步骤三:配置Prometheus

  1. 配置Istio的监控指标。
    1. 登录容器服务管理控制台
    2. 在控制台左侧导航栏,单击集群
    3. 集群列表页面,单击目标集群名称或者目标集群右侧操作列下的详情
    4. 在集群管理页左侧导航栏,选择配置管理 > 配置项
    5. 配置项页面顶部设置命名空间为Istio-sysytem,单击prometheus操作列下的编辑
    6. 编辑面板文本框中添加配置信息,然后单击确定
  2. 删除Prometheus Pod,使Prometheus配置生效。
    1. 登录容器服务管理控制台
    2. 在控制台左侧导航栏,单击集群
    3. 集群列表页面,单击目标集群名称或者目标集群右侧操作列下的详情
    4. 在集群管理页左侧导航栏,选择工作负载 > 容器组
    5. 容器组页面单击Prometheus操作列下的删除
    6. 删除容器组对话框单击确定
  3. 执行以下命令,查看Prometheus配置中的job_name
    kubectl --kubeconfig <kubeconfig位置> get cm prometheus -n istio-system -o jsonpath={.data.prometheus\\.yml} | grep job_name

    预期输出:

    - job_name: 'istio-mesh'
    - job_name: 'envoy-stats'
    - job_name: 'istio-policy'
    - job_name: 'istio-telemetry'
    - job_name: 'pilot'
    - job_name: 'sidecar-injector'
    - job_name: prometheus
      job_name: kubernetes-apiservers
      job_name: kubernetes-nodes
      job_name: kubernetes-nodes-cadvisor
    - job_name: kubernetes-service-endpoints
    - job_name: kubernetes-service-endpoints-slow
      job_name: prometheus-pushgateway
    - job_name: kubernetes-services
    - job_name: kubernetes-pods
    - job_name: kubernetes-pods-slow

步骤四:生成监控指标数据

  1. 执行以下命令,在ACK集群中部署podinfo示例应用。
    1. 下载podinfo示例应用的YAML文件。关于podinfo示例应用的下载地址,请参见podinfo
    2. 执行以下命令,部署podinfo示例应用。
      kubectl --kubeconfig <kubeconfig位置> apply -f <podinfo位置>/kustomize/deployment.yaml -n test
      kubectl --kubeconfig <kubeconfig位置> apply -f <podinfo位置>/kustomize/service.yaml -n test
  2. 执行以下命令,请求podinfo应用,以产生监控指标数据。
    podinfo_pod=$(k get po -n test -l app=podinfo -o jsonpath={.items..metadata.name})
    for i in {1..10}; do
       kubectl --kubeconfig "$USER_CONFIG" exec $podinfo_pod -c podinfod -n test -- curl -s podinfo:9898/version
      echo
    done
  3. 在Envoy容器内确认监控指标已生成。
    1. 执行以下命令,请求Envoy确认是否包含istio_requests_total监控指标。
      kubectl --kubeconfig <kubeconfig位置> exec $podinfo_pod -n test -c istio-proxy -- curl -s localhost:15090/stats/prometheus | grep istio_requests_total

      预期输出:

      :::: istio_requests_total ::::
      # TYPE istio_requests_total counter
      istio_requests_total{response_code="200",reporter="destination",source_workload="podinfo",source_workload_namespace="test",source_principal="spiffe://cluster.local/ns/test/sa/default",source_app="podinfo",source_version="unknown",source_cluster="c199d81d4e3104a5d90254b2a210914c8",destination_workload="podinfo",destination_workload_namespace="test",destination_principal="spiffe://cluster.local/ns/test/sa/default",destination_app="podinfo",destination_version="unknown",destination_service="podinfo.test.svc.cluster.local",destination_service_name="podinfo",destination_service_namespace="test",destination_cluster="c199d81d4e3104a5d90254b2a210914c8",request_protocol="http",response_flags="-",grpc_response_status="",connection_security_policy="mutual_tls",source_canonical_service="podinfo",destination_canonical_service="podinfo",source_canonical_revision="latest",destination_canonical_revision="latest"} 10
      
      istio_requests_total{response_code="200",reporter="source",source_workload="podinfo",source_workload_namespace="test",source_principal="spiffe://cluster.local/ns/test/sa/default",source_app="podinfo",source_version="unknown",source_cluster="c199d81d4e3104a5d90254b2a210914c8",destination_workload="podinfo",destination_workload_namespace="test",destination_principal="spiffe://cluster.local/ns/test/sa/default",destination_app="podinfo",destination_version="unknown",destination_service="podinfo.test.svc.cluster.local",destination_service_name="podinfo",destination_service_namespace="test",destination_cluster="c199d81d4e3104a5d90254b2a210914c8",request_protocol="http",response_flags="-",grpc_response_status="",connection_security_policy="unknown",source_canonical_service="podinfo",destination_canonical_service="podinfo",source_canonical_revision="latest",destination_canonical_revision="latest"} 10
    2. 执行以下命令,请求Envoy确认是否包含istio_request_duration监控指标。
      kubectl --kubeconfig <kubeconfig位置> exec $podinfo_pod -n test -c istio-proxy -- curl -s localhost:15090/stats/prometheus | grep istio_request_duration

      预期输出:

      :::: istio_request_duration ::::
      # TYPE istio_request_duration_milliseconds histogram
      istio_request_duration_milliseconds_bucket{response_code="200",reporter="destination",source_workload="podinfo",source_workload_namespace="test",source_principal="spiffe://cluster.local/ns/test/sa/default",source_app="podinfo",source_version="unknown",source_cluster="c199d81d4e3104a5d90254b2a210914c8",destination_workload="podinfo",destination_workload_namespace="test",destination_principal="spiffe://cluster.local/ns/test/sa/default",destination_app="podinfo",destination_version="unknown",destination_service="podinfo.test.svc.cluster.local",destination_service_name="podinfo",destination_service_namespace="test",destination_cluster="c199d81d4e3104a5d90254b2a210914c8",request_protocol="http",response_flags="-",grpc_response_status="",connection_security_policy="mutual_tls",source_canonical_service="podinfo",destination_canonical_service="podinfo",source_canonical_revision="latest",destination_canonical_revision="latest",le="0.5"} 10
      
      istio_request_duration_milliseconds_bucket{response_code="200",reporter="destination",source_workload="podinfo",source_workload_namespace="test",source_principal="spiffe://cluster.local/ns/test/sa/default",source_app="podinfo",source_version="unknown",source_cluster="c199d81d4e3104a5d90254b2a210914c8",destination_workload="podinfo",destination_workload_namespace="test",destination_principal="spiffe://cluster.local/ns/test/sa/default",destination_app="podinfo",destination_version="unknown",destination_service="podinfo.test.svc.cluster.local",destination_service_name="podinfo",destination_service_namespace="test",destination_cluster="c199d81d4e3104a5d90254b2a210914c8",request_protocol="http",response_flags="-",grpc_response_status="",connection_security_policy="mutual_tls",source_canonical_service="podinfo",destination_canonical_service="podinfo",source_canonical_revision="latest",destination_canonical_revision="latest",le="1"} 10
      ...

结果验证

  1. 使用负载均衡的方式对外暴露Prometheus服务。具体操作,请参见使用Service对外暴露应用
  2. 登录容器服务管理控制台
  3. 在控制台左侧导航栏,单击集群
  4. 集群列表页面,单击目标集群名称或者目标集群右侧操作列下的详情
  5. 在集群管理页左侧导航栏,选择网络 > 服务
  6. 服务页面单击Prometheus外部端点列下的IP地址。
  7. 在Prometheus中输入istio_requests_total,单击Execute
    如下图所示,说明Prometheus采集应用监控指标成功。prometheus