--- title: Argo CD tags: Argo --- # Argo CD > [name=李俊毅] > [time=Wed, Sep 16, 2020 4:57 PM] --- ## Agenda * 介紹 * 架構 * 建置 * 通知 * 監控 * 擴展 * 問題 --- ## 介紹 ---- Argo CD是用於Kubernetes的聲明性GitOps持續交付工具 ---- ### 什麼是 GitOps GitOps 是 Weaveworks 提出的一種持續交付(CD)的概念,透過 Git 來聲明基礎設施(infrastructure)和應用程序(applications)希望的狀態 ---- ### GitOps 概念  ---- ### GitOps 運作模式  --- ## 架構 ----  ---- ### API Server <font color=#BE6143>API服務器是gRPC / REST服務器,它公開了Web UI,CLI和CI / CD系統使用的API。它具有以下職責:</font> * <font size=5>application management and status reporting</font> * <font size=5>invoking of application operations (e.g. sync, rollback, user-defined actions)</font> * <font size=5>repository and cluster credential management (stored as K8s secrets)</font> * <font size=5>authentication and auth delegation to external identity providers</font> * <font size=5>RBAC enforcement</font> * <font size=5>listener/forwarder for Git webhook events</font> ---- ### Repository Server <font color=#BE6143>儲存庫服務器是一個內部服務,用於維護保存應用程序清單的Git儲存庫的本地緩存。提供以下輸入時,它負責生成和返回Kubernetes清單:</font> * <font size=5>repository URL</font> * <font size=5>revision (commit, tag, branch)</font> * <font size=5>application path</font> * <font size=5>template specific settings: parameters, ksonnet environments, helm values.yaml</font> ---- ### Application Controller <font color=#BE6143>應用程序控制器是Kubernetes控制器,它持續監視正在運行的應用程序,並將當前的活動狀態與所需的目標狀態(如回購中所指定的)進行比較。它檢測【OutOfSync】應用程序狀態並有選擇地採取糾正措施。它負責為生命週期事件(PreSync,Sync,PostSync,SyncFail)調用任何用戶定義的掛鉤。</font> ---- ### 生命週期 * <font size=5>【PreSync】在部署新版本的應用程序之前,使用掛鉤執行數據庫架構遷移。</font> * <font size=5>使用【Sync】鉤子編排比Kubernetes滾動更新策略更複雜的複雜部署。</font> * <font size=5>【PostSync】部署後使用掛鉤運行集成和運行狀況檢查。</font> * <font size=5>【SyncFail】如果同步操作失敗,則使用掛鉤運行清理或終結器邏輯。PS: SyncFail鉤子僅從v1.2開始可用</font> ---- ### 特性 * <font size=5>將應用程序自動部署到指定的目標環境</font> * <font size=5>支持多種配置管理/模板工具(Kustomize,Helm,Ksonnet,Jsonnet,plain-YAML)</font> * <font size=5>能夠管理和部署到多個集群</font> * <font size=5>支持身份驗證</font> * <font size=5>多租戶和RBAC授權策略</font> * <font size=5>透過Git存儲庫中提交的任何應用程序配置進行 Rollback/Roll-anywhere</font> * <font size=5>自動或手動將應用程序同步到所需狀態</font> * <font size=5>透過 Web UI 提供應用程序活動的實時視圖</font> * <font size=5>提供 CLI 來自動化與CI集成</font> ---- * <font size=5>Webhook集成</font> * <font size=5>PreSync,Sync,PostSync掛鉤可支持複雜的應用程序推出(例如,藍色/綠色和金絲雀升級)</font> * <font size=5>普羅米修斯指標</font> --- ## 建置 ---- ### 安裝 Argo CD CLI ``` brew install argocd ``` <font size=3> [參考文獻](https://argoproj.github.io/argo-cd/cli_installation/#installation)</font> ---- ### 建置 Argo CD 服務(Non-HA) ``` kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml ``` ---- ### 建置 Argo CD 服務(HA) ``` kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v1.7.6/manifests/ha/install.yaml ``` ---- ### 取得登入Server密碼,帳號 admin ``` kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2 ``` ---- ### 設定 Repositories ----  ---- #### 將私鑰填入欄中,公鑰需設定在azure devops上  ---- ### 設定Applications ----  ----  ----  ----  ---- ## 配置 Argo CD 多租戶 ---- ### 登入Argo CD server ``` argocd login <ARGOCD_SERVER_IP> ``` ---- ### 註冊k8s群集 ``` argocd cluster add <CLUSTER_NAME> ``` ---- ## 通知 ---- ### 建立 argocd notifications 服務 ``` kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/stable/manifests/install.yaml ``` ---- ### 設定觸發條件 ``` apiVersion: v1 kind: ConfigMap metadata: name: argocd-notifications-cm namespace: argocd data: config.yaml: | triggers: - name: on-sync-succeeded enabled: true ``` ---- ### 設定發送渠道,以slack為例 ---- 0.添加 annotations 到 Argo CD應用程序或項目來訂閱通知 ``` metadata: annotations: recipients.argocd-notifications.argoproj.io:slack:<my-channel> ``` ---- 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集成 ``` apiVersion: v1 kind: Secret metadata: name: argocd-notifications-secret stringData: notifiers.yaml: | slack: token: <my-token> username: <override-username> # optional username icon: <override-icon> # optional icon for the message (supports both emoij and url notation) ``` --- ## 監控 ---- ### 設定 Prometheus config #### Argocd ``` argocd-metrics:8082/metrics argocd-server-metrics:8083/metrics ``` #### Argocd-notifications ``` argocd-notifications-controller-metrics:9001 ``` ---- ### 匯入 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,需額外設定 * <font color=#BE6143>在 Application 新增過濾條件</font> * <font color=#BE6143>安裝 argo-rollouts</font> ---- ### 在 Application 新增過濾條件 ``` spec: ignoreDifferences: - group: apps kind: Deployment jsonPointers: - /spec/replicas - group: apps kind: StatefulSet jsonPointers: - /spec/replicas ``` ---- ### 安裝 argo-rollouts https://argoproj.github.io/argo-rollouts/ ---- #### 建置 ``` kubectl create namespace argo-rollouts kubectl apply -n argo-rollouts -f https://raw.githubusercontent.com/argoproj/argo-rollouts/stable/manifests/install.yaml ``` ----
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up