Flagger on ASM·基於Mixerless Telemetry實現漸進式灰度發布系列 1 遙測數據


簡介: 服務網格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,從而實現漸進式灰度發布。

3d017eb88d621b3d89d2adf4561d35a1.png

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

前提條件

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(可選)

f92a68dbd9d2428f347abb0eccb5fc17.png

點擊確定后,我們將在控制平面看到ASM生成的相關EnvoyFilter列表:

6b998570374366c7e22c3c92ca9b5266.png

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一行,點擊編輯。

e99b7f58e38a2fb5e85fbd342becfca2.png

prometheus.yaml配置中,將scrape_configs.yaml中的配置追加到scrape_configs中。

24b21ed0f59c779f29fb929b8d36772c.png

保存配置后,左側導航欄選擇工作負載>容器組,在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,得到結果如下圖所示。

728223d4754ad0b162549d34e9ceeae8.png

原文鏈接

本文為阿里雲原創內容,未經允許不得轉載。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM