ArgoCD
支持的版本: ArgoCD v2.9+, Argo Rollouts v1.6+ 最后更新: July 11, 2026
目录
什么是 ArgoCD?
ArgoCD 是 Kubernetes 的声明式 GitOps 持续交付工具。它通过将 Git 仓库中定义的目标状态与集群中的实际状态同步,自动将应用程序部署到 Kubernetes 集群。
作为 CNCF 毕业项目,ArgoCD 已成为基于 GitOps 的 Kubernetes 部署的事实标准,被全球数千家组织采用。
主要优势
GitOps 原生
- Git 作为唯一事实来源: 所有应用程序配置均存储在 Git 中
- 声明式部署: 定义目标状态,其余工作由 ArgoCD 处理
- 审计追踪: 通过 Git commits 完整记录所有更改的历史
- 回滚: 可立即回滚到任意先前状态
多集群管理
- 集中式控制: 通过单个 ArgoCD 实例管理数百个集群
- ApplicationSet: 基于模板的多集群部署
- Cluster Generator: 基于标签动态定位集群
企业就绪
- RBAC: 细粒度的基于角色的访问控制
- SSO 集成: 支持 OIDC、SAML、LDAP
- 多租户: 基于 Project 的隔离
- 高可用性: 适用于生产环境的 HA 部署
开发者体验
- Web UI: 可视化应用程序管理和监控
- CLI: 功能完整的命令行界面
- 通知: Slack、Teams、电子邮件、webhook 集成
- 健康监控: 内置和自定义健康检查
架构概览
核心组件
| 组件 | 描述 | 副本数 (HA) |
|---|---|---|
| API Server | 处理所有 API 请求、身份验证和 RBAC | 2+ |
| Repository Server | 克隆仓库、生成 manifests、缓存结果 | 2+ |
| Application Controller | 监控应用程序、协调状态 | 2+(分片) |
| Redis | 用于 repo server 和 controller 的缓存层 | 3 (HA) |
| Dex | 用于 SSO 集成的 OIDC 提供程序 | 2+ |
| Notification Controller | 在事件发生时发送通知 | 1+ |
| ApplicationSet Controller | 管理 ApplicationSet 资源 | 1+ |
数据流
核心概念
Application
Application CRD 是 ArgoCD 中的主要资源。它定义:
- 源: 获取 manifests 的位置(Git repo、Helm chart、OCI)
- 目标位置: 部署位置(cluster 和 namespace)
- 同步策略: 如何处理同步
Project
Project 提供逻辑分组和访问控制:
- 限制可使用的仓库
- 限制目标 cluster 和 namespace
- 定义允许/拒绝的资源
ApplicationSet
ApplicationSet 可使用 generators 通过单一定义管理多个应用程序:
- List Generator: 静态值列表
- Cluster Generator: 定位已注册的 clusters
- Git Generator: 扫描仓库目录/文件
- Matrix/Merge: 组合多个 generators
Sync
同步使集群状态与目标状态一致:
- 手动同步: 由用户触发
- 自动同步: Git 更改时自动执行
- Self-Heal: 自动修正偏差
- Prune: 删除孤立资源
子指南导航
| 指南 | 描述 |
|---|---|
| 安装 | 安装方法、CLI 设置、HA 配置、EKS 集成 |
| 应用程序 | Application CRD、源类型、健康检查、hooks、App of Apps |
| 同步策略 | 同步策略、waves、windows、diffing、retry 配置 |
| ApplicationSets | 所有 generators、templating、渐进式同步、多集群模式 |
| 流量管理 | Argo Rollouts、blue-green、canary、分析、ingress 集成 |
| Projects 与 RBAC | AppProject、RBAC 策略、多租户、JWT tokens |
| 安全性 | SSO 集成、secret 管理、TLS、审计日志 |
| 通知 | 通知服务、triggers、templates、subscriptions |
| 最佳实践 | 仓库模式、性能调优、故障排除、EKS 提示 |
快速开始
1. 安装 ArgoCD
bash
# Create namespace
kubectl create namespace argocd
# Install ArgoCD
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Wait for pods to be ready
kubectl wait --for=condition=Ready pods --all -n argocd --timeout=300s2. 访问 UI
bash
# Port forward to access locally
kubectl port-forward svc/argocd-server -n argocd 8080:4433. 获取初始密码
bash
# Retrieve the initial admin password
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d && echo4. 通过 CLI 登录
bash
# Install CLI (macOS)
brew install argocd
# Login
argocd login localhost:8080
# Change password (recommended)
argocd account update-password5. 部署您的第一个应用程序
bash
# Create application via CLI
argocd app create guestbook \
--repo https://github.com/argoproj/argocd-example-apps.git \
--path guestbook \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
# Sync the application
argocd app sync guestbook或者以声明方式:
yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: HEAD
path: guestbook
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true版本兼容性
2026 年 7 月更新:ArgoCD 3.x 补丁版本
ArgoCD v3.4.5 于 2026 年 7 月 9 日发布。3.4 系列是当前稳定发布系列,下一个次要版本 v3.5.0 已达到 rc2。下表基于 2.x 时代编写——请查看 ArgoCD 发布页面,获取按版本划分的最新支持信息。
Kubernetes 兼容性
| ArgoCD 版本 | Kubernetes 版本 |
|---|---|
| 2.13.x | 1.28 - 1.31 |
| 2.12.x | 1.27 - 1.30 |
| 2.11.x | 1.26 - 1.29 |
| 2.10.x | 1.25 - 1.28 |
| 2.9.x | 1.24 - 1.27 |
Amazon EKS 兼容性
| EKS 版本 | 推荐的 ArgoCD |
|---|---|
| 1.31 | 2.13.x |
| 1.30 | 2.12.x - 2.13.x |
| 1.29 | 2.11.x - 2.12.x |
| 1.28 | 2.10.x - 2.11.x |
Argo Rollouts 兼容性
| Rollouts 版本 | ArgoCD 版本 | 功能 |
|---|---|---|
| 1.7.x | 2.10+ | 分析改进 |
| 1.6.x | 2.9+ | 通知集成 |
| 1.5.x | 2.8+ | 渐进式交付 |
后续步骤
- 安装指南: 为生产环境设置 ArgoCD
- 应用程序指南: 了解 Application CRD
- ApplicationSets 指南: 多集群部署
资源
测验
要测试所学知识,请尝试 ArgoCD 安装测验。