关于prometheus:Flagger-on-ASM基于Mixerless-Telemetry实现渐进式灰度发布系列-1-遥测数据

11次阅读

共计 8489 个字符,预计需要花费 22 分钟才能阅读完成。

简介:服务网格 ASM 的 Mixerless Telemetry 技术,为业务容器提供了无侵入式的遥测数据。遥测数据一方面作为监控指标被 ARMPS/prometheus 采集,用于服务网格可观测性;另一方面被 HPA 和 flaggers 应用,成为利用级扩缩容和渐进式灰度公布的基石。本系列聚焦于遥测数据在利用级扩缩容和渐进式灰度公布上的实际,将分三篇介绍遥测数据(监控指标)、利用级扩缩容,和渐进式灰度公布。

服务网格 ASM 的 Mixerless Telemetry 技术,为业务容器提供了无侵入式的遥测数据。遥测数据一方面作为监控指标被 ARMPS/prometheus 采集,用于服务网格可观测性;另一方面被 HPA 和 flaggers 应用,成为利用级扩缩容和渐进式灰度公布的基石。

本系列聚焦于遥测数据在利用级扩缩容和渐进式灰度公布上的实际,将分三篇介绍遥测数据(监控指标)、利用级扩缩容,和渐进式灰度公布。

总体架构

本系列的总体架构如下图所示:

  1. ASM 下发 Mixerless Telemetry 相干的 EnvoyFilter 配置到各 ASM sidecar(envoy),启用利用级监控指标的采集。
  2. 业务流量通过 Ingress Gateway 进入,各 ASM sidecar 开始采集相干监控指标。
  3. Prometheus 从各 POD 上采集监控指标。
  4. HPA 通过 Adapter 从 Prometheus 查问相干 POD 的监控指标,并依据配置进行扩缩容。
  5. Flagger 通过 Prometheus 查问相干 POD 的监控指标,并依据配置向 ASM 发动 VirtualService 配置更新。
  6. ASM 下发 VirtualService 配置到各 ASM sidecar,从而实现渐进式灰度公布。

Flagger 渐进式公布流程

Flagger 官网形容了渐进式公布流程,这里翻译如下:

  1. 探测并更新灰度 Deployment 到新版本
  2. 灰度 POD 实例数从 0 开始扩容
  3. 期待灰度 POD 实例数达到 HPA 定义的最小正本数量
  4. 灰度 POD 实例衰弱检测
  5. 由 flagger-loadtester 实例发动 acceptance-test 验证
  6. 灰度公布在验证失败时终止
  7. 由 flagger-loadtester 实例发动 load-test 验证
  8. 在配置流量复制时开始从生产全流量复制到灰度
  9. 每分钟从 Prometheus 查问并检测申请成功率和申请提早等监控指标
  10. 灰度公布在监控指标不符预期的数量达到阈值时终止
  11. 达到配置中迭代的次数后进行流量复制
  12. 开始切流到灰度 POD 实例
  13. 更新生产 Deployment 到新版本
  14. 期待生产 Deployment 滚动降级结束
  15. 期待生产 POD 实例数达到 HPA 定义的最小正本数量
  16. 生产 POD 实例衰弱检测
  17. 切流回生产 POD 实例
  18. 灰度 POD 实例缩容至 0
  19. 发送灰度公布剖析后果告诉

原文如下:

With the above configuration, Flagger will run a canary release with the following steps:

  • detect new revision (deployment spec, secrets or configmaps changes)
  • scale from zero the canary deployment
  • wait for the HPA to set the canary minimum replicas
  • check canary pods health
  • run the acceptance tests
  • abort the canary release if tests fail
  • start the load tests
  • mirror 100% of the traffic from primary to canary
  • check request success rate and request duration every minute
  • abort the canary release if the metrics check failure threshold is reached
  • stop traffic mirroring after the number of iterations is reached
  • route live traffic to the canary pods
  • promote the canary (update the primary secrets, configmaps and deployment spec)
  • wait for the primary deployment rollout to finish
  • wait for the HPA to set the primary minimum replicas
  • check primary pods health
  • switch live traffic back to primary
  • scale to zero the canary
  • send notification with the canary analysis result

前提条件

  • 已创立 ACK 集群,详情请参见创立 Kubernetes 托管版集群。
  • 已创立 ASM 实例,详情请参见创立 ASM 实例。

Setup Mixerless Telemetry

本篇将介绍如何基于 ASM 配置并采集利用级监控指标 (比方申请数量总数istio_requests_total 和申请提早 istio_request_duration 等)。次要步骤包含创立 EnvoyFilter、校验 envoy 遥测数据和校验 Prometheus 采集遥测数据。

1 EnvoyFilter

登录 ASM 控制台,左侧导航栏抉择 服务网格 > 网格治理 ,并进入 ASM 实例的 性能配置 页面。

  • 勾选开启采集 Prometheus 监控指标
  • 点选启用自建 Prometheus,并填入 Prometheus 服务地址: `prometheus:9090(本系列将应用社区版 Prometheus,后文将应用这个配置)。如果应用阿里云产品 ARMS,请参考集成 ARMS Prometheus 实现网格监控。
  • 勾选启用 Kiali(可选)

点击确定后,咱们将在管制立体看到 ASM 生成的相干 EnvoyFilter 列表:

2 Prometheus

2.1 Install

执行如下命令装置 Prometheus(残缺脚本参见:demo\_mixerless.sh)。

kubectl --kubeconfig "$USER_CONFIG" apply -f $ISTIO_SRC/samples/addons/prometheus.yaml

2.2 Config Scrape

装置完 Prometheus,咱们须要为其配置增加 istio 相干的监控指标。登录 ACK 控制台,左侧导航栏抉择 配置管理 > 配置项 ,在istio-system 下找到 prometheus 一行,点击 编辑

prometheus.yaml 配置中,将 scrape\_configs.yaml 中的配置追加到 scrape_configs 中。

保留配置后,左侧导航栏抉择 工作负载 > 容器组 ,在istio-system 下找到 prometheus 一行,删除 Prometheus POD,以确保配置在新的 POD 中失效。

能够执行如下命令查看 Prometheus 配置中的job_name

kubectl --kubeconfig "$USER_CONFIG" 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

Mixerless 验证

1 podinfo

1.1 部署

应用如下命令部署本系列的示例利用 podinfo:

kubectl --kubeconfig "$USER_CONFIG" apply -f $PODINFO_SRC/kustomize/deployment.yaml -n test
kubectl --kubeconfig "$USER_CONFIG" apply -f $PODINFO_SRC/kustomize/service.yaml -n test

1.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

2 确认生成(Envoy)

本系列重点关注的监控指标项是 istio_requests_totalistio_request_duration。首先,咱们在 envoy 容器内确认这些指标曾经生成。

2.1 istio\_requests\_total

应用如下命令申请 envoy 获取 stats 相干指标数据,并确认蕴含istio_requests_total

kubectl --kubeconfig "$USER_CONFIG" 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.2 istio\_request\_duration

应用如下命令申请 envoy 获取 stats 相干指标数据,并确认蕴含istio_request_duration

kubectl --kubeconfig "$USER_CONFIG" 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
...

3 确认采集(Prometheus)

最初,咱们验证 Envoy 生成的监控指标数据,是否被 Prometheus 实时采集上来。对外裸露 Prometheus 服务,并应用浏览器申请该服务。而后在查问框输出istio_requests_total,失去后果如下图所示。

版权申明:本文内容由阿里云实名注册用户自发奉献,版权归原作者所有,阿里云开发者社区不领有其著作权,亦不承当相应法律责任。具体规定请查看《阿里云开发者社区用户服务协定》和《阿里云开发者社区知识产权爱护指引》。如果您发现本社区中有涉嫌剽窃的内容,填写侵权投诉表单进行举报,一经查实,本社区将立即删除涉嫌侵权内容。

正文完
 0