Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Application Management

Creating apps

UI

  • β€œ+ NEW APP”, fill in name, project, sync policy, repo URL, revision, path, cluster, namespace
  • quick, but not version controlled

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-policy automated --auto-prune --self-heal

# helm chart
argocd app create redis --repo https://charts.bitnami.com/bitnami --helm-chart redis \
  --revision 17.8.0 --dest-server https://kubernetes.default.svc --dest-namespace redis \
  --helm-set auth.enabled=false

# kustomize
argocd app create myapp --repo <repo> --path overlays/production \
  --dest-server https://kubernetes.default.svc --dest-namespace production \
  --kustomize-image myapp=myregistry.com/myapp:v2.0.0
argocd app list
argocd app get myapp
argocd app sync myapp
argocd app diff myapp
argocd app history myapp
argocd app rollback myapp <ID>   # auto-sync must be disabled
argocd app terminate-op myapp
argocd app delete myapp

Declarative

  • preferred, just a manifest applied to the argocd namespace
  • Application must be in the Argo CD namespace (unless apps-in-any-namespace is enabled)
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: production
  source:
    repoURL: https://github.com/example/app.git
    targetRevision: main
    path: kubernetes/production
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m
  ignoreDifferences:
    - group: apps
      kind: Deployment
      jsonPointers:
        - /spec/replicas
  • ignoreDifferences needs the RespectIgnoreDifferences=true sync option to also be honored during sync, otherwise only the diff ignores it

Deleting an app

  • without the finalizer the app is deleted but its resources stay (like PVs, to avoid data loss)
  • resources-finalizer.argocd.argoproj.io (same as .../foreground) cascades the delete
  • resources-finalizer.argocd.argoproj.io/background for background deletion
  • argocd app delete myapp --cascade=false leaves resources

App of Apps

  • one parent Application whose path contains child Application manifests
  • parent syncs the children, children sync the workloads
  • good for bootstrapping a cluster
  • children must live in the argocd namespace and destination of parent is argocd
apps/
β”œβ”€β”€ app-of-apps.yaml   # parent
└── apps/
    β”œβ”€β”€ frontend.yaml
    └── backend.yaml
# parent
spec:
  project: default
  source:
    repoURL: https://github.com/example/apps.git
    targetRevision: main
    path: apps
  destination:
    server: https://kubernetes.default.svc
    namespace: argocd
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
  • per-environment: one parent per environments/<env>/apps dir

Repositories

  • credentials are stored as Secrets with label argocd.argoproj.io/secret-type: repository
argocd repo add https://github.com/example/private.git --username myuser --password <token>
argocd repo add git@github.com:example/private.git --ssh-private-key-path ~/.ssh/id_rsa
argocd repo add https://charts.bitnami.com/bitnami --type helm --name bitnami
argocd repo list
argocd repo rm <url>
apiVersion: v1
kind: Secret
metadata:
  name: private-repo
  namespace: argocd
  labels:
    argocd.argoproj.io/secret-type: repository
stringData:
  type: git            # or helm
  url: https://github.com/example/private-repo.git
  username: myuser
  password: <token>
  # sshPrivateKey: | ...  for ssh urls
  • credential templates: label argocd.argoproj.io/secret-type: repo-creds with a URL prefix (https://github.com/example), applies to all matching repos
    • this replaces the old repository.credentials in argocd-cm

Projects

  • AppProject, logical grouping + guard rails
    • restrict source repos
    • restrict destinations (cluster + namespace)
    • restrict cluster-scoped and namespaced kinds
    • per-project RBAC roles, sync windows
  • default project allows everything, can’t be deleted but can be locked down
  • an Application belongs to exactly one project
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: team-app
  namespace: argocd
spec:
  description: Team application project
  sourceRepos:
    - https://github.com/team/app-repo.git
  destinations:
    - namespace: team-dev
      server: https://kubernetes.default.svc
  clusterResourceWhitelist: []   # no cluster-scoped resources
  namespaceResourceWhitelist:
    - group: apps
      kind: Deployment
    - group: ''
      kind: Service
  namespaceResourceBlacklist:
    - group: ''
      kind: ResourceQuota
  orphanedResources:
    warn: true
  syncWindows:
    - kind: allow
      schedule: '0 9 * * 1-5'
      duration: 8h
      applications: ['*']
      manualSync: true
    - kind: deny
      schedule: '0 0 * * 0,6'
      duration: 24h
      applications: ['*']
  • empty whitelist = nothing allowed, empty blacklist = nothing denied
  • cluster-scoped: clusterResourceWhitelist/Blacklist, namespaced: namespaceResourceWhitelist/Blacklist
  • deny windows win over allow; manualSync: true lets manual syncs through a deny window
argocd proj create myproject
argocd proj add-source myproject https://github.com/example/repo.git
argocd proj add-destination myproject https://kubernetes.default.svc production
argocd proj allow-cluster-resource myproject "" Namespace
argocd proj allow-namespace-resource myproject apps Deployment
argocd proj list
argocd proj get myproject

ApplicationSet

  • templates + generators produce many Applications
  • generated apps are owned by the ApplicationSet (deleted with it)
  • template params use {{param}} (or {{.param}} with goTemplate: true)

List

spec:
  generators:
    - list:
        elements:
          - cluster: production
            url: https://prod-cluster.example.com
          - cluster: staging
            url: https://staging-cluster.example.com
  template:
    metadata:
      name: '{{cluster}}-myapp'
    spec:
      project: default
      source:
        repoURL: https://github.com/example/app.git
        targetRevision: main
        path: kubernetes
      destination:
        server: '{{url}}'
        namespace: myapp

Git directory

  • one app per directory
generators:
  - git:
      repoURL: https://github.com/example/apps.git
      revision: main
      directories:
        - path: apps/*
# template: name '{{path.basename}}', path '{{path}}'

Git file

  • one app per JSON/YAML config file, keys become params
generators:
  - git:
      repoURL: https://github.com/example/app-config.git
      revision: main
      files:
        - path: "configs/*.yaml"
# template: '{{app.name}}', '{{app.repoURL}}'

Cluster

  • one app per cluster registered in Argo CD, filter on labels
  • params: name, server, metadata.labels.*
generators:
  - clusters:
      selector:
        matchLabels:
          environment: production

Matrix

  • cartesian product of two generators
generators:
  - matrix:
      generators:
        - git:
            repoURL: https://github.com/example/apps.git
            revision: main
            directories:
              - path: apps/*
        - list:
            elements:
              - env: production
                cluster: https://prod.example.com
              - env: staging
                cluster: https://staging.example.com
# template: '{{path.basename}}-{{env}}'
  • other generators: merge, SCM provider, pull request, cluster decision resource