DevOps Peach

GitOps with Argo CD · Argo CD at Scale · Lesson 2 of 4

ApplicationSets and generators

An ApplicationSet uses a generator (list, cluster, Git, matrix) to produce parameters and stamps out one Application per set from a template.

Practice interactively →

An ApplicationSet is a template plus a generator. The generator produces a list of parameter sets; the ApplicationSet controller renders one Application per set and keeps them in step — adding, updating and (by default) deleting them.

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: shop-api
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
    - list:
        elements:
          - { env: dev,     cluster: https://kubernetes.default.svc }
          - { env: staging, cluster: https://kubernetes.default.svc }
          - { env: prod,    cluster: https://prod-sg.example.com:6443 }
  template:
    metadata:
      name: 'shop-api-{{.env}}'
    spec:
      project: shop
      source:
        repoURL: https://github.com/example-org/shop-config.git
        targetRevision: main
        path: 'apps/shop-api/overlays/{{.env}}'
      destination:
        server: '{{.cluster}}'
        namespace: 'shop-{{.env}}'

Generators

Generator Produces one set per… Typical use
List element you write in the YAML A few fixed environments
Cluster cluster registered in Argo CD (filter by labels) Install the same add-on on every cluster
Git directories folder matching a path, e.g. apps/* One app per folder in a monorepo
Git files JSON/YAML file, e.g. envs/*/config.json Per-environment parameters kept in Git
Matrix combination of two generators Every app × every cluster
Merge merged result of generators Defaults plus overrides
Pull request / SCM provider open PR or repository Preview environments per PR
generators:
  - matrix:
      generators:
        - git:
            repoURL: https://github.com/example-org/platform-config.git
            revision: main
            directories: [{ path: addons/* }]
        - clusters:
            selector: { matchLabels: { env: prod } }
# template name: '{{.path.basename}}-{{.name}}'

Safety switches

argocd appset create shop-api-appset.yaml
argocd appset list
argocd appset get shop-api

Practice interactively →