The DevOps track showed you the GitOps idea and a first Argo CD Application. This lesson opens the argoproj/argo-cd repository itself: which process does what, how a sync is ordered, how one ApplicationSet replaces fifty hand-written Applications, how projects fence teams in, and which knobs matter when Argo CD manages hundreds of apps across many clusters.
- Name the Argo CD components and say which one to look at when a sync is slow, wrong or failing
- Order a deployment with sync waves and PreSync, PostSync and SyncFail hooks
- Generate Applications per directory or per cluster with an ApplicationSet
- Restrict a team to its repositories, clusters and resource kinds with an AppProject
- Tune and shard the application controller for large installations
Inside the repository: one binary, several jobs
Argo CD is written in Go and ships as one container image whose entrypoint decides which component to run. The top-level folders of the repository map almost one-to-one onto the processes you see in the argocd namespace, which makes the code a useful map when you debug.
| Folder | Runs as | Job |
|---|---|---|
server/ | argocd-server | gRPC/REST API behind the UI and CLI: auth, RBAC, sync and rollback requests, Git webhooks |
reposerver/ | argocd-repo-server | Clones Git (or pulls Helm and OCI charts), caches them, and renders plain manifests |
controller/ | argocd-application-controller | Compares live state with rendered desired state, sets sync and health status, runs syncs |
applicationset/ | argocd-applicationset-controller | Turns one ApplicationSet into many Applications using generators |
notification_controller/ | argocd-notifications-controller | Sends Slack, email or webhook messages on triggers such as sync failed |
commitserver/ | argocd-commit-server | Optional: writes rendered manifests back to Git for the source hydrator |
Two more pieces complete the picture: Redis, a cache the controller and API server share (it holds no state you cannot rebuild), and Dex, an optional identity broker for SSO. The gitops-engine/ folder holds the reusable diff-and-sync library that the controller is built on, and resource_customizations/ holds the Lua health checks that teach Argo CD when a custom resource counts as Healthy.
Debug by component. Manifests look wrong or a Helm value is ignored: read the repo server logs. Status stuck at Unknown or syncs queue up: the application controller. Login, RBAC or webhook problems: the API server.
How a sync is ordered: phases, waves and hooks
A sync is not one big kubectl apply. Argo CD runs it in phases — PreSync, Sync, PostSync, plus SyncFail if something breaks — and inside each phase it applies resources in waves. A wave is the integer in the argocd.argoproj.io/sync-wave annotation. Everything defaults to wave 0, waves can be negative, and Argo CD applies the lowest wave first and waits for it to be healthy before moving on.
A hook is any resource carrying the argocd.argoproj.io/hook annotation, usually a Job. A PreSync hook that fails stops the sync before your Deployment is touched, which makes it the right place for a database migration or a pre-flight check. PostSync hooks run only after every resource is Healthy, so they suit smoke tests and notifications.
apiVersion: batch/v1
kind: Job
metadata:
name: db-migrate
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
spec:
backoffLimit: 1
template:
spec:
restartPolicy: Never
containers:
- name: migrate
image: ghcr.io/example/orders:1.8.0
command: ["./manage", "migrate"]- Put a Namespace, CRDs or a Secret in wave
-1so they exist before the workloads in wave 0 that need them. - When pruning, the order is reversed: higher waves are deleted first.
- Hooks do not run during a selective sync (syncing only some resources from the UI).
ApplicationSets: stop copying Applications
Once you have a dozen services or clusters, hand-writing one Application each turns into copy-paste drift. An ApplicationSet pairs a generator, which produces a list of parameter sets, with a template that becomes one Application per parameter set. The generators in the docs include List, Cluster, Git (directories or files), Matrix and Merge (combine two generators), Pull Request, SCM Provider, Cluster Decision Resource and Plugin.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: cluster-addons
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- git:
repoURL: https://github.com/example/platform.git
revision: HEAD
directories:
- path: addons/*
template:
metadata:
name: '{{.path.basename}}'
spec:
project: platform
source:
repoURL: https://github.com/example/platform.git
targetRevision: HEAD
path: '{{.path.path}}'
destination:
server: https://kubernetes.default.svc
namespace: '{{.path.basename}}'
syncPolicy:
syncOptions:
- CreateNamespace=trueThe Cluster generator is the multi-cluster workhorse: it emits one parameter set per cluster registered in Argo CD, optionally filtered by label, so env=prod clusters get the production overlay automatically. Matrix a Cluster generator with a Git generator and you get every add-on on every matching cluster from about thirty lines of YAML.
Deleting an ApplicationSet deletes the Applications it generated, and with the resources finalizer those delete their workloads too. Review ApplicationSet changes as carefully as you would a production deploy.
AppProjects: guard rails per team
Every Application belongs to an AppProject, and the default project allows everything. For anything shared, create one project per team that says which repositories it may deploy from, which cluster and namespace pairs it may deploy to, and which resource kinds it may create. A team that cannot create a ClusterRole through Argo CD cannot escalate its own permissions through Git either.
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: payments
namespace: argocd
spec:
sourceRepos:
- https://github.com/example/payments-*
destinations:
- server: https://kubernetes.default.svc
namespace: payments-*
clusterResourceWhitelist: []
namespaceResourceBlacklist:
- group: ''
kind: ResourceQuotaAn empty clusterResourceWhitelist means no cluster-scoped resources at all. Projects also carry roles whose JWT tokens let a CI job trigger syncs for that project only, and sync windows that block automatic syncs during, say, a quarter-end freeze.
Running Argo CD at scale
By default the controller re-checks Git for every Application about every three minutes (timeout.reconciliation in the argocd-cm ConfigMap) and handles work with 20 status processors and 10 operation processors. The high-availability guide suggests about 50 and 25 for roughly a thousand applications. Configure Git webhooks so a push triggers a refresh at once instead of waiting for the next poll.
- Shard the controller when it manages many clusters: raise the replica count of
argocd-application-controllerand setARGOCD_CONTROLLER_REPLICASto the same number; clusters are spread across replicas. - Scale the repo server horizontally when rendering is the bottleneck, which is common with large Helm charts or many Kustomize overlays.
- Use the HA manifests (Redis with Sentinel, multiple API servers) for production, and pin a released version instead of tracking
stable. - Install with
kubectl apply --server-side: some CRDs, such as ApplicationSet, exceed the annotation size limit of client-side apply.
Newer releases add the source hydrator (beta since v3.5): instead of rendering Helm or Kustomize in memory, Argo CD renders once, commits the plain manifests to a branch, and syncs from there, so every change to what actually runs is a reviewable diff. It is disabled by default and needs the commit server.