成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

使用Flux+Flagger+Istio+Kubernetes實戰GitOps云原生漸進式(金絲雀)交付

云計算 云原生
漸進交付是高級部署模式(如金絲雀canaries、功能標志feature flags和A/B測試A/B testing)的總稱。漸進交付技術通過讓應用程序開發人員和 SRE 團隊對爆炸半徑blast radius進行細粒度控制,從而降低在生產中引入新軟件版本的風險。

[[403388]]

在這篇指南中,你將獲得使用 Kubernetes 和 Istio 使用 GitOps 進行漸進式交付(Progressive Delivery)的實際經驗。

介紹

Demo: https://github.com/stefanprodan/gitops-istio

GitOps 是什么?

GitOps 是一種進行持續交付的方式,它使用 Git 作為聲明性(declarative)基礎設施和工作負載(workloads)的真實來源。對于 Kubernetes,這意味著使用 git push 而不是 kubectl apply/delete 或 helm install/upgrade。

在這個 workshop 中,您將使用 GitHub 來托管配置存儲庫,并將 Flux 作為 GitOps 交付解決方案。

什么是漸進式交付?

漸進交付是高級部署模式(如金絲雀canaries、功能標志feature flags和A/B測試A/B testing)的總稱。漸進交付技術通過讓應用程序開發人員和 SRE 團隊對爆炸半徑blast radius進行細粒度控制,從而降低在生產中引入新軟件版本的風險。

在這個 workshop 中,您將使用 Flagger 和 Prometheus 為您的應用程序自動執行 Canary 發布和 A/B Testing。

準備工作

您將需要具有 LoadBalancer 支持的 Kubernetes 集群 v1.16 或更高版本。出于測試目的,您可以使用帶有 2 個 CPU 和 4GB 內存的 Minikube。

使用 Homebrew 安裝 flux CLI:

  1. brew install fluxcd/tap/flux 

macOS AMD64/ARM64、Linux AMD64/ARM 和 Windows 的二進制文件可在 flux2 release page 下載。

驗證您的集群是否滿足前提條件:

  1. flux check --pre 

使用 Homebrew 安裝 jq 和 yq:

  1. brew install jq yq 

Fork 這個倉庫并克隆它:

  1. git clone https://github.com/<YOUR-USERNAME>/gitops-istio 
  2. cd gitops-istio 

Cluster bootstrap

使用 flux bootstrap 命令,您可以在 Kubernetes 集群上安裝 Flux 并將其配置為從 Git 存儲庫管理自身。如果集群上存在 Flux 組件,則 bootstrap 命令將在需要時執行升級。

通過指定您的 GitHub 存儲庫 fork URL 來引導 Flux:

  1. flux bootstrap git \ 
  2.   --author-email=<YOUR-EMAIL> \ 
  3.   --url=ssh://git@github.com/<YOUR-USERNAME>/gitops-istio \ 
  4.   --branch=main \ 
  5.   --path=clusters/my-cluster 

上面的命令需要 ssh-agent,如果您使用的是 Windows,請參閱 flux bootstrap github 文檔。

在引導時,Flux 生成一個 SSH key 并打印 public key。為了用 git 同步你的集群狀態,你需要復制 public key 并使用 write 創建一個 deploy key 訪問你的 GitHub 倉庫。在 GitHub 上轉到 Settings > Deploy keys 點擊 Add deploy key, 勾選☑️ Allow write access,粘貼 Flux public key 并單擊 Add key。

當 Flux 訪問你的存儲庫時,它會做以下事情:

  • 安裝 Istio operator
  • 等待 Istio 控制平面準備好
  • 安裝 Flagger、Prometheus 和 Grafana
  • 創建 Istio 公共網關
  • 創建 prod 命名空間namespace
  • 創建負載測試器(load tester) deployment
  • 創建前端(frontend) deployment 和金絲雀canary
  • 創建后端(backend) deployment 和金絲雀canary

使用 Istio 引導集群時,定義 apply 順序很重要。對于要使用 Istio sidecar 注入的應用程序 pod,Istio 控制平面必須在應用程序之前啟動并運行。

在 Flux v2 中,你可以通過定義對象之間的依賴關系來指定執行順序。例如,在 clusters/my-cluster/apps.yaml 中我們告訴 Flux,apps 的協調取決于一個 istio-system :

  1. apiVersion: kustomize.toolkit.fluxcd.io/v1beta1 
  2. kind: Kustomization 
  3. metadata: 
  4.   name: apps 
  5.   namespace: flux-system 
  6. spec: 
  7.   interval: 30m0s 
  8.   dependsOn: 
  9.     - name: istio-system 
  10.   sourceRef: 
  11.     kind: GitRepository 
  12.     name: flux-system 
  13.   path: ./apps 

首先觀測 Flux 安裝 Istio,然后觀測 demo apps:

  1. watch flux get kustomizations 

您可以使用以下命令跟蹤 Flux reconciliation 日志:

  1. flux logs --all-namespaces --follow --tail=10 

Istio 定制和升級

您可以使用位于 istio/system/profile.yaml 的 IstioOperator 資源自定義 Istio 安裝:

  1. apiVersion: install.istio.io/v1alpha1 
  2. kind: IstioOperator 
  3. metadata: 
  4.   name: istio-default 
  5.   namespace: istio-system 
  6. spec: 
  7.   profile: demo 
  8.   components: 
  9.     pilot: 
  10.       k8s: 
  11.         resources: 
  12.           requests: 
  13.             cpu: 10m 
  14.             memory: 100Mi 

修改 Istio 設置后,您可以將更改推送到 git,Flux 將在集群上應用它。Istio operator 將根據您的更改重新配置 Istio 控制平面。

當新的 Istio 版本可用時,update-istio GitHub Action workflow 工作流將打開一個pull request,其中包含升級 Istio Operator 所需的清單更新。新的 Istio 版本通過 e2e workflow 在 Kubernetes Kind 上進行測試,當 PR 合并到主分支時,Flux 將在集群內升級 Istio。

應用程序引導

當 Flux 將 Git 存儲庫與您的集群同步時,它將創建前端/后端部署(frontend/backend deployment)、HPA 和一個金絲雀對象canary object。Flagger 使用 canary 定義創建了一系列對象:Kubernetes deployments、ClusterIP services、Istio 目標規則(destination rules)和虛擬服務(virtual services)。這些對象在網格(mesh)上公開(expose)應用程序,并推動金絲雀分析(canary analysis)和推廣(promotion)。

  1. # applied by Flux 
  2. deployment.apps/frontend 
  3. horizontalpodautoscaler.autoscaling/frontend 
  4. canary.flagger.app/frontend 
  5.  
  6. # generated by Flagger 
  7. deployment.apps/frontend-primary 
  8. horizontalpodautoscaler.autoscaling/frontend-primary 
  9. service/frontend 
  10. service/frontend-canary 
  11. service/frontend-primary 
  12. destinationrule.networking.istio.io/frontend-canary 
  13. destinationrule.networking.istio.io/frontend-primary 
  14. virtualservice.networking.istio.io/frontend 

檢查 Flagger 是否成功初始化了金絲雀:

  1. kubectl -n prod get canaries 
  2.  
  3. NAME       STATUS        WEIGHT 
  4. backend    Initialized   0 
  5. frontend   Initialized   0 

當 frontend-primary 部署上線時,Flager 會將所有流量路由到主 Pod,并將 frontend 部署 scale 到零。

使用以下命令查找 Istio 入口網關(ingress gateway)地址:

  1. kubectl -n istio-system get svc istio-ingressgateway -ojson | jq .status.loadBalancer.ingress 

打開瀏覽器并導航到入口地址,您將看到前端 UI。

金絲雀發布

Flagger 實現了一個控制循環,該控制循環在測量關鍵性能指標(如 HTTP 請求成功率、請求平均持續時間和 pod 運行狀況)的同時,逐步將流量轉移到金絲雀。在分析 KPI 的基礎上,將金絲雀升級或中止,并將分析結果發布到 Slack。

金絲雀分析由以下任何對象的更改觸發:

部署 PodSpec(容器鏡像、命令、端口、環境等)

ConfigMaps 和 Secrets 作為卷(volumes)掛載或映射到環境變量

對于不接收恒定流量的工作負載,Flagger 可以配置一個 webhook,當它被調用時,將啟動一個目標工作負載的負載測試。canary 配置可以在 apps/backend/canary.yaml 上找到。

從 GitHub 拉取更改:

  1. git pull origin main 

要觸發后端應用程序的金絲雀部署,請碰撞容器鏡像:

  1. yq e '.images[0].newTag="5.0.1"' -i ./apps/backend/kustomization.yaml 

提交和推送更改:

  1. git add -A && \ 
  2. git commit -m "backend 5.0.1" && \ 
  3. git push origin main 

告訴 Flux 拉取更改或等待一分鐘讓 Flux 自行檢測更改:

  1. flux reconcile source git flux-system 

觀測 Flux 將您的集群與最新提交進行協調:

  1. watch flux get kustomizations 

幾秒鐘后,Flager 檢測到部署修訂(deployment revision)已更改并開始新的 rollout:

  1. $ kubectl -n prod describe canary backend 
  2.  
  3. Events: 
  4.  
  5. New revision detected! Scaling up backend.prod 
  6. Starting canary analysis for backend.prod 
  7. Pre-rollout check conformance-test passed 
  8. Advance backend.prod canary weight 5 
  9. ... 
  10. Advance backend.prod canary weight 50 
  11. Copying backend.prod template spec to backend-primary.prod 
  12. Promotion completed! Scaling down backend.prod 

在分析過程中,Grafana 可以監控金絲雀的進程。您可以通過端口轉發訪問儀表板:

  1. kubectl -n istio-system port-forward svc/flagger-grafana 3000:80 

Istio 儀表板的 URL 是 http://localhost:3000/d/flagger-istio/istio-canary?refresh=10s&orgId=1&var-namespace=prod&var-primary=backend-primary&var-canary=backend

請注意,如果在金絲雀分析(canary analysis)期間對部署應用了新的更改,Flagger 將重新啟動分析階段。

A/B 測試

除了加權路由(weighted routing),Flagger 還可以配置為根據 HTTP 匹配條件將流量路由到金絲雀。在 A/B 測試場景中,您將使用 HTTP headers 或 cookie 來定位用戶的特定部分。這對于需要會話(session)關聯的前端應用程序特別有用。

您可以通過指定 HTTP 匹配條件和迭代次數來啟用 A/B 測試:

  1. analysis: 
  2.   # schedule interval (default 60s) 
  3.   interval: 10s 
  4.   # max number of failed metric checks before rollback 
  5.   threshold: 10 
  6.   # total number of iterations 
  7.   iterations: 12 
  8.   # canary match condition 
  9.   match: 
  10.     - headers: 
  11.         user-agent: 
  12.           regex: ".*Firefox.*" 
  13.     - headers: 
  14.         cookie: 
  15.           regex: "^(.*?;)?(type=insider)(;.*)?$" 

上述配置將針對 Firefox 用戶和擁有內部 cookie 的用戶運行兩分鐘的分析。前端配置可以在 apps/frontend/canary.yaml 中找到。

通過更新前端容器鏡像觸發部署:

  1. yq e '.images[0].newTag="5.0.1"' -i ./apps/frontend/kustomization.yaml 
  2.  
  3. git add -A && \ 
  4. git commit -m "frontend 5.0.1" && \ 
  5. git push origin main 
  6.  
  7. flux reconcile source git flux-system 

Flager 檢測到部署修訂已更改并開始 A/B 測試:

  1. $ kubectl -n istio-system logs deploy/flagger -f | jq .msg 
  2.  
  3. New revision detected! Scaling up frontend.prod 
  4. Waiting for frontend.prod rollout to finish: 0 of 1 updated replicas are available 
  5. Pre-rollout check conformance-test passed 
  6. Advance frontend.prod canary iteration 1/10 
  7. ... 
  8. Advance frontend.prod canary iteration 10/10 
  9. Copying frontend.prod template spec to frontend-primary.prod 
  10. Waiting for frontend-primary.prod rollout to finish: 1 of 2 updated replicas are available 
  11. Promotion completed! Scaling down frontend.prod 

您可以通過以下方式監控所有金絲雀:

  1. $ watch kubectl get canaries --all-namespaces 
  2.  
  3. NAMESPACE   NAME      STATUS        WEIGHT 
  4. prod        frontend  Progressing   100 
  5. prod        backend   Succeeded     0 

基于 Istio 指標的回滾

Flagger 使用 Istio 遙測提供的指標來驗證金絲雀工作負載。前端應用 analysis 定義了兩個指標檢查:

  1. metrics: 
  2.    - name: error-rate 
  3.      templateRef: 
  4.        name: error-rate 
  5.        namespace: istio-system 
  6.      thresholdRange: 
  7.        max: 1 
  8.      interval: 30s 
  9.    - name: latency 
  10.      templateRef: 
  11.        name: latency 
  12.        namespace: istio-system 
  13.      thresholdRange: 
  14.        max: 500 
  15.      interval: 30s 

用于檢查錯誤率(error rate)和延遲的 Prometheus 查詢,位于 flagger-metrics.yaml。

在金絲雀分析期間,您可以生成 HTTP 500 errors 和高延遲(high latency)來測試 Flagger 的回滾。

生成 HTTP 500 errors:

  1. watch curl -b 'type=insider' http://<INGRESS-IP>/status/500 

生成延遲:

  1. watch curl -b 'type=insider' http://<INGRESS-IP>/delay/1 

當失敗的檢查次數達到金絲雀分析閾值(threshold)時,流量將路由回主服務器,金絲雀縮放為零,并將推出(rollout)標記為失敗。

  1. $ kubectl -n istio-system logs deploy/flagger -f | jq .msg 
  2.  
  3. New revision detected! Scaling up frontend.prod 
  4. Pre-rollout check conformance-test passed 
  5. Advance frontend.prod canary iteration 1/10 
  6. Halt frontend.prod advancement error-rate 31 > 1 
  7. Halt frontend.prod advancement latency 2000 > 500 
  8. ... 
  9. Rolling back frontend.prod failed checks threshold reached 10 
  10. Canary failed! Scaling down frontend.prod 

您可以使用針對 Prometheus、Datadog 和 Amazon CloudWatch 的自定義指標檢查來擴展分析。

有關為 Slack、MS Teams、Discord 或 Rocket 配置 canary 分析警報的信息,請參閱文檔。

責任編輯:姜華 來源: 黑客下午茶
相關推薦

2021-07-13 06:35:11

Argo Rollou GitOpsKubernetes

2022-08-22 10:40:40

Kubernete部署分析運行

2021-06-24 08:25:38

flux2GitOps 云原生

2022-02-17 13:09:55

金絲雀部署服務集群測試

2023-04-11 07:59:56

Kruise漸進式交付

2022-11-30 08:00:00

金絲雀部署IT測試

2021-07-29 05:09:54

Linkerd金絲雀部署Flagger

2023-10-08 07:34:04

2014-12-16 13:51:55

華為eSpace UC統一通信

2010-04-27 13:41:42

云計算

2022-12-06 17:32:18

2021-06-15 05:52:33

Linkerd canary網絡技術

2023-09-28 07:34:33

2021-10-08 20:12:22

微服務架構Service

2024-11-04 16:04:06

2021-02-28 07:52:24

蠕蟲數據金絲雀

2024-01-02 07:37:52

FlaggerKubernetesIstio

2021-07-16 06:40:19

Argo RollouAnalysis云原生

2024-11-20 09:39:56

漸進式遷移云策略云支出
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人久草 | 先锋资源亚洲 | 日韩在线资源 | 欧美一级二级在线观看 | 免费在线性爱视频 | 秋霞国产 | 日本久久黄色 | 亚洲第一在线 | 日韩午夜一区二区三区 | 色综合视频 | 成人精品一区二区三区中文字幕 | 黄色网页在线 | 精品国产乱码久久久久久丨区2区 | 在线播放中文 | a级大片| 久热爱| 九九99久久 | 一区二区不卡视频 | 大象一区 | 成人三级在线播放 | 精品少妇v888av | 青青草av在线播放 | 99热精品在线 | 久久999| 天堂一区在线 | 久久狠狠 | 日韩欧美精品 | 天堂久| 欧美自拍一区 | 久久中文字幕一区 | 欧美一区二区三区在线视频 | 午夜小电影 | 天天爽夜夜骑 | 一区二区三区av | 午夜伦理影院 | 一区免费视频 | 8x国产精品视频一区二区 | 国产一级片网站 | 国产视频一区二区 | 国产激情在线观看 | 91久久久久|