Argo CD
李俊毅
Wed, Sep 16, 2020 4:57 PM
Agenda
介紹
Argo CD是用於Kubernetes的聲明性GitOps持續交付工具
什麼是 GitOps
GitOps 是 Weaveworks 提出的一種持續交付(CD)的概念,透過 Git 來聲明基礎設施(infrastructure)和應用程序(applications)希望的狀態
GitOps 概念
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
GitOps 運作模式
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
架構
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
API Server
API服務器是gRPC / REST服務器,它公開了Web UI,CLI和CI / CD系統使用的API。它具有以下職責:
- application management and status reporting
- invoking of application operations (e.g. sync, rollback, user-defined actions)
- repository and cluster credential management (stored as K8s secrets)
- authentication and auth delegation to external identity providers
- RBAC enforcement
- listener/forwarder for Git webhook events
Repository Server
儲存庫服務器是一個內部服務,用於維護保存應用程序清單的Git儲存庫的本地緩存。提供以下輸入時,它負責生成和返回Kubernetes清單:
- repository URL
- revision (commit, tag, branch)
- application path
- template specific settings: parameters, ksonnet environments, helm values.yaml
Application Controller
應用程序控制器是Kubernetes控制器,它持續監視正在運行的應用程序,並將當前的活動狀態與所需的目標狀態(如回購中所指定的)進行比較。它檢測【OutOfSync】應用程序狀態並有選擇地採取糾正措施。它負責為生命週期事件(PreSync,Sync,PostSync,SyncFail)調用任何用戶定義的掛鉤。
生命週期
- 【PreSync】在部署新版本的應用程序之前,使用掛鉤執行數據庫架構遷移。
- 使用【Sync】鉤子編排比Kubernetes滾動更新策略更複雜的複雜部署。
- 【PostSync】部署後使用掛鉤運行集成和運行狀況檢查。
- 【SyncFail】如果同步操作失敗,則使用掛鉤運行清理或終結器邏輯。PS: SyncFail鉤子僅從v1.2開始可用
特性
- 將應用程序自動部署到指定的目標環境
- 支持多種配置管理/模板工具(Kustomize,Helm,Ksonnet,Jsonnet,plain-YAML)
- 能夠管理和部署到多個集群
- 支持身份驗證
- 多租戶和RBAC授權策略
- 透過Git存儲庫中提交的任何應用程序配置進行 Rollback/Roll-anywhere
- 自動或手動將應用程序同步到所需狀態
- 透過 Web UI 提供應用程序活動的實時視圖
- 提供 CLI 來自動化與CI集成
- Webhook集成
- PreSync,Sync,PostSync掛鉤可支持複雜的應用程序推出(例如,藍色/綠色和金絲雀升級)
- 普羅米修斯指標
建置
安裝 Argo CD CLI
參考文獻
建置 Argo CD 服務(Non-HA)
建置 Argo CD 服務(HA)
取得登入Server密碼,帳號 admin
設定 Repositories
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
將私鑰填入欄中,公鑰需設定在azure devops上
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
設定Applications
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
配置 Argo CD 多租戶
登入Argo CD server
註冊k8s群集
通知
建立 argocd notifications 服務
設定觸發條件
設定發送渠道,以slack為例
0.添加 annotations 到 Argo CD應用程序或項目來訂閱通知
1.創建 Slack 應用程式 https://api.slack.com/apps?new_app=1

2.創建完畢後設定 OAuth & Permissions

3.發送slack權限需添加 chat:write:bot,如要在Slack通知服務中使用可選的用戶名和圖標替代要添加 chat:write.customize

4.滾動回到頂部,單擊“將應用程序安裝到工作區”按鈕並確認安裝

5.安裝完成後,複製OAuth令牌

6.最後,使用OAuth令牌在argocd-notifications-secret秘密中配置Slack集成
監控
設定 Prometheus config
Argocd
Argocd-notifications
匯入 Grafana dashboard
Argocd
https://github.com/argoproj/argo-cd/blob/master/examples/dashboard.json

Argocd-notifications
https://argoproj-labs.github.io/argocd-notifications/grafana-dashboard.json

擴展
因gitops有聲明式特性不能直接用HPA,需額外設定
- 在 Application 新增過濾條件
- 安裝 argo-rollouts
在 Application 新增過濾條件
安裝 argo-rollouts
https://argoproj.github.io/argo-rollouts/
建置