3. Argo CD 安装与部署:Helm Chart安装、Operator安装、高可用部署模式选择
Argo CD 的部署方式直接影响 GitOps 流水线的稳定性与运维成本。本章聚焦三种主流安装路径——Helm Chart、Operator 以及高可用模式,帮助你在不同集群规模和运维能力下做出合理选择。
3.1 安装方式对比总览
下表从运维复杂度、功能扩展性、生产就绪度三个维度对比三种安装方式,便于快速决策。
| 安装方式 | 运维复杂度 | 功能扩展性 | 生产就绪度 | 推荐场景 |
|---|---|---|---|---|
| Helm Chart | 中等 | 高(values.yaml 可调参数多) | 高 | 已有 Helm 管理经验、需精细控制参数 |
| Operator | 低(声明式管理) | 中(依赖 CRD 扩展) | 高 | 自动化运维、多集群、需自动升级 |
| 静态 YAML / Kustomize | 低(直接 apply) | 低(手动修改) | 中 | 快速验证、Demo、最小化部署 |
选型建议:生产环境优先选择 Helm Chart 或 Operator。Helm 适合需要深度定制参数的团队;Operator 适合希望“声明式管理 Argo CD 自身”的 GitOps 成熟团队。
3.2 使用 Helm Chart 安装 Argo CD
Helm Chart 是社区推荐的安装方式,支持通过 values.yaml 精细控制每个组件的副本数、资源限制、Ingress 配置、TLS 证书等。
3.2.1 添加仓库与安装
# 添加 Argo CD Helm 仓库
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
# 创建命名空间
kubectl create namespace argocd
# 使用 Helm 安装(默认配置)
helm install argocd argo/argo-cd \
--namespace argocd \
--create-namespace \
--version 7.1.0
3.2.2 生产级 values.yaml 关键参数
以下片段展示高可用部署的核心调优项:
# values.yaml 生产级配置片段
global:
# 镜像拉取策略
imagePullPolicy: IfNotPresent
# 控制平面组件
controller:
replicas: 2
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "1"
memory: "1Gi"
# API Server
server:
replicas: 2
ingress:
enabled: true
ingressClassName: nginx
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
hosts:
- argocd.example.com
tls:
- secretName: argocd-tls
hosts:
- argocd.example.com
# Repo Server
repoServer:
replicas: 2
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
# Redis 高可用
redis:
enabled: true
architecture: replication
auth:
enabled: true
password: "your-redis-password"
replica:
replicaCount: 3
注意:Redis 密码必须通过 Kubernetes Secret 注入,避免明文写在 values.yaml 中。生产环境建议使用
--set redis.auth.existingSecret 引用外部 Secret。
3.3 使用 Operator 安装 Argo CD
Argo CD Operator 基于 Operator SDK 构建,将 Argo CD 实例定义为 CRD(Custom Resource Definition),通过 ArgoCD 资源对象声明式管理整个生命周期。
3.3.1 安装 Operator
# 通过 OLM(Operator Lifecycle Manager)安装
kubectl create -f https://operatorhub.io/install/argocd-operator.yaml
# 等待 Operator 就绪
kubectl get csv -n operators | grep argocd
3.3.2 声明 ArgoCD 实例
apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
name: example-argocd
namespace: argocd
spec:
# 高可用模式
ha:
enabled: true
redis:
replicas: 3
# 组件副本数
controller:
replicas: 2
server:
replicas: 2
insecure: false
route:
enabled: true
tls:
termination: edge
repo:
replicas: 2
resources:
requests:
cpu: "250m"
memory: "256Mi"
# 自动升级策略
version: v2.12.0
Operator 优势:升级 Argo CD 只需修改
spec.version,Operator 自动完成滚动升级、数据迁移、配置合并。适合多集群统一管理场景。
3.4 高可用部署模式选择
Argo CD 的高可用(HA)模式通过多副本、组件分离、外部 Redis 哨兵/集群实现。下图展示 HA 模式的组件拓扑。
3.5 高可用模式参数对比
下表列出 Helm Chart 与 Operator 两种方式下 HA 模式的核心参数差异:
| 组件 | Helm Chart 参数 | Operator 参数 | 说明 |
|---|---|---|---|
| API Server 副本 | server.replicas: 2 |
spec.server.replicas: 2 |
建议 ≥2,配合 PodAntiAffinity |
| Controller 副本 | controller.replicas: 2 |
spec.controller.replicas: 2 |
多副本通过 Leader Election 协调 |
| Repo Server 副本 | repoServer.replicas: 2 |
spec.repo.replicas: 2 |
缓存 Git 仓库,多副本共享 Redis |
| Redis 模式 | redis.architecture: replication |
spec.ha.redis.replicas: 3 |
生产必须使用哨兵或集群模式 |
| Ingress / Route | server.ingress.enabled: true |
spec.server.route.enabled: true |
Operator 原生支持 OpenShift Route |
3.6 部署模式决策树
根据团队运维能力和集群规模,可参考以下决策路径:
3.7 安装后验证清单
部署完成后,执行以下验证步骤确保集群就绪:
- Pod 状态检查:
kubectl get pods -n argocd,所有 Pod 应为Running且READY为1/1或2/2。 - Service 可达性:
kubectl get svc -n argocd,确认argocd-server的 ClusterIP 或 LoadBalancer 正常。 - 初始密码获取:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d - CLI 登录测试:
argocd login <server-address> --username admin --password <password> --insecure - Redis 哨兵健康:
kubectl exec -n argocd <redis-pod> -- redis-cli -a <password> sentinel master mymaster
生产建议:安装完成后立即修改 admin 默认密码,并配置 RBAC 与 SSO 集成。HA 模式下建议为 Redis 设置
persistentVolumeClaim 防止重启丢数据。