TExcelTAD
Home › GitOps: Argo CD & Flux › App of Apps

App of Apps

Applications are Kubernetes objects, so Argo CD can deploy them like any other object. The app of apps pattern uses one hand-applied root Application whose source is a folder of other Applications. After that single kubectl apply, every app, including Argo CD's own configuration, is created, changed and deleted through Git.

text
kubectl apply -f root.yaml   (once, at bootstrap)
        │
        ▼
Application "root"  ──source──> linkly-deploy/clusters/production/
                                  ├── platform.yaml        Application -> infrastructure/ (Gateway, cert-manager)
                                  ├── linkly.yaml          Application -> linkly chart, production values
                                  └── linkly-project.yaml  AppProject "linkly"

Build the folder and validate it

bash · try it yourself
mkdir -p clusters/production && cd clusters/production
app() {   # name, path, namespace, wave
cat > $1.yaml <<EOF
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: $1
  namespace: argocd
  annotations: {argocd.argoproj.io/sync-wave: "$4"}
  finalizers: [resources-finalizer.argocd.argoproj.io]
spec:
  project: $( [ $1 = platform ] && echo platform || echo linkly )
  source: {repoURL: https://github.com/acme/linkly-deploy.git, targetRevision: main, path: $2}
  destination: {server: https://kubernetes.default.svc, namespace: $3}
  syncPolicy:
    automated: {prune: true, selfHeal: true}
    syncOptions: [CreateNamespace=true]
EOF
}
app platform infrastructure gateway-system -1
app linkly-production apps/production linkly-prod 0
cat > linkly-project.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: linkly
  namespace: argocd
  annotations: {argocd.argoproj.io/sync-wave: "-2"}
spec:
  sourceRepos: [https://github.com/acme/linkly-deploy.git]
  destinations: [{server: https://kubernetes.default.svc, namespace: linkly-*}]
EOF
cd ../..
cat > root.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: {name: root, namespace: argocd}
spec:
  project: default
  source: {repoURL: https://github.com/acme/linkly-deploy.git, targetRevision: main, path: clusters/production}
  destination: {server: https://kubernetes.default.svc, namespace: argocd}
  syncPolicy:
    automated: {prune: true, selfHeal: true}
EOF
kubeconform -strict -summary root.yaml clusters/production
yq -N '.metadata.annotations["argocd.argoproj.io/sync-wave"] + "  " + .kind + "/" + .metadata.name' clusters/production/*.yaml | sort -n
Summary: 4 resources found in 4 files - Valid: 4, Invalid: 0, Errors: 0, Skipped: 0
-2  AppProject/linkly
-1  Application/platform
0  Application/linkly-production

The platform child uses a platform AppProject owned by the platform team (defined in the platform repository, not shown). The root Application's destination namespace is argocd, because that is where the child Application objects live; each child then deploys to its own namespace. The root uses the default project (or a dedicated, admin-only bootstrap project), since it must be allowed to create Applications and AppProjects.

Ordering child apps: the health catch

The annotations put the AppProject first (wave -2), then the platform (wave -1), then linkly. But waves only wait for health, and since Argo CD 1.8 the built-in health check for Application objects was removed: a child Application counts as healthy as soon as it exists, so the root moves to the next wave without waiting for the platform's Gateway to be ready. To make waves between apps meaningful, restore an Application health check in argocd-cm (this snippet is from the Argo CD docs' 1.7→1.8 upgrade notes):

yaml
data:
  resource.customizations.health.argoproj.io_Application: |
    hs = {}
    hs.status = "Progressing"
    hs.message = ""
    if obj.status ~= nil then
      if obj.status.health ~= nil then
        hs.status = obj.status.health.status
        if obj.status.health.message ~= nil then
          hs.message = obj.status.health.message
        end
      end
    end
    return hs

Generating the children with Helm

Writing near-identical Applications by hand gets old. A common variant makes the root's source a small Helm chart whose template loops over a values list:

bash · try it yourself
mkdir -p apps-chart/templates
printf 'apiVersion: v2\nname: apps\nversion: 0.1.0\n' > apps-chart/Chart.yaml
cat > apps-chart/values.yaml <<'EOF'
repoURL: https://github.com/acme/linkly-deploy.git
apps:
  - {name: linkly-staging, path: apps/staging, namespace: linkly-staging}
  - {name: linkly-production, path: apps/production, namespace: linkly-prod}
EOF
cat > apps-chart/templates/apps.yaml <<'EOF'
{{- range .Values.apps }}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: {{ .name }}
  namespace: argocd
spec:
  project: linkly
  source: {repoURL: {{ $.Values.repoURL }}, targetRevision: main, path: {{ .path }}}
  destination: {server: https://kubernetes.default.svc, namespace: {{ .namespace }}}
  syncPolicy: {automated: {prune: true, selfHeal: true}}
{{- end }}
EOF
helm template root apps-chart | kubeconform -strict -summary -
helm template root apps-chart | yq -N '.metadata.name + " -> " + .spec.destination.namespace'
Summary: 2 resources found parsing stdin - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0
linkly-staging -> linkly-staging
linkly-production -> linkly-prod

This works, but it is exactly what ApplicationSets were designed to replace, with generators that read Git, clusters and pull requests instead of a hand-maintained list. App of apps remains the standard way to bootstrap: one root that installs the ApplicationSets, the AppProjects and Argo CD's own config.

Cascading deletes: be careful

The root has prune: true, so deleting a child YAML from Git deletes that Application, and the child's finalizer then deletes all of its objects. One bad commit that removes clusters/production/linkly.yaml takes production down. Protect critical children with argocd.argoproj.io/sync-options: Prune=false or by leaving out the finalizer, and require reviews on clusters/.

Test yourself

What is the destination namespace of a root Application in the app-of-apps pattern?

  1. The app's namespace, e.g. linkly-prod
  2. The namespace where Argo CD's Application objects live, usually argocd
  3. kube-system
  4. default, always

Why don't sync waves between child Applications wait for the earlier child to become healthy by default?

  1. Waves don't work on CRDs
  2. Argo CD has no built-in health check for Application objects since 1.8, so they count as healthy immediately
  3. Child apps always sync in parallel
  4. Waves only apply to hooks

A commit deletes clusters/production/linkly.yaml from a root app with prune enabled and finalizers on the children. What happens?

  1. Nothing
  2. The linkly Application is deleted and its finalizer deletes linkly's objects
  3. Argo CD recreates the file
  4. Only the Application object disappears, the workload stays