Skip to content

GitOps patterns with Argo CD#

Lens premium subscription feature. See details on Lens Pricing.

Argo CD is configured in Git, not in Lens K8S IDE. This page shows the manifests teams write, and what each one looks like once Lens K8S IDE reads it back from the cluster. Every manifest here runs against a cluster with Argo CD installed, and uses the public Argo CD example apps repository.

For the day-to-day tasks, see Manage GitOps with Argo CD.

An Application deploys a Git path#

An Application tells Argo CD which Git path to deploy and where to deploy it.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: helm-guestbook
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/argoproj/argocd-example-apps.git
    targetRevision: HEAD
    path: helm-guestbook
  destination:
    server: https://kubernetes.default.svc
    namespace: helm-guestbook
  syncPolicy:
    automated: {}
    syncOptions:
      - CreateNamespace=true

In Argo CD > Applications, this Application moves from OutOfSync to Synced, and Health settles on Healthy. An Application without syncPolicy.automated stays OutOfSync until you sync it, which is the state you want while you review a change before it lands.

Automated sync does not undo live drift

An Application with syncPolicy.automated still shows OutOfSync after someone edits a live resource, because automated sync reacts to Git changes. Add selfHeal: true to the policy if you want Argo CD to revert manual edits on its own.

A project restricts what an Application may do#

An AppProject restricts which repositories an Application may deploy from and which destinations it may deploy to. Use one per team or per tier.

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: platform
  namespace: argocd
spec:
  description: Platform services owned by the infrastructure team
  sourceRepos:
    - https://github.com/argoproj/argocd-example-apps.git
  destinations:
    - server: https://kubernetes.default.svc
      namespace: '*'
  clusterResourceWhitelist:
    - group: '*'
      kind: '*'

Set spec.project: platform on an Application to place it in the project. Argo CD > Projects shows each project with its description and its count of source repositories. The Applications list carries a Project column, so you can sort the fleet by owner.

An ApplicationSet templates one Application per environment#

An ApplicationSet generates one Application per element of a generator. Use it when the same workload ships to several regions or stages.

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook-regions
  namespace: argocd
spec:
  generators:
    - list:
        elements:
          - region: eu-west
          - region: us-east
  template:
    metadata:
      name: 'guestbook-{{region}}'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: HEAD
        path: guestbook
      destination:
        server: https://kubernetes.default.svc
        namespace: 'guestbook-{{region}}'
      syncPolicy:
        syncOptions:
          - CreateNamespace=true

This creates guestbook-eu-west and guestbook-us-east. Both appear in Argo CD > Applications alongside hand-written Applications, and the set itself appears in Argo CD > Application Sets with its generator type. Neither generated Application syncs on its own, because the template sets no automated policy.

Sync waves order a rollout#

Teams that deploy a database migration before the workload that reads it, or that raise a maintenance page around a release, control the order with sync waves. A wave is an integer annotation on a resource in Git:

metadata:
  annotations:
    argocd.argoproj.io/sync-wave: "2"

Argo CD applies resources by phase first, then by wave from lowest to highest, then by kind and name. Resources without the annotation sit in wave 0, and negative waves run before them. Hooks carry a phase of their own:

metadata:
  annotations:
    argocd.argoproj.io/hook: PreSync

The sync-waves example combines both. It runs a PreSync schema-upgrade job first, then a backend in wave 0. A maintenance-page job follows in wave 1, the frontend in wave 2, and a job that removes the maintenance page in wave 3.

Lens K8S IDE shows the result of the ordering rather than the wave numbers, which live in Git. An Application stuck at Progressing usually means a wave is waiting on a hook that has not finished.

An app of apps bootstraps a cluster#

A single parent Application whose Git path contains nothing but child Application manifests is the standard way to bootstrap a cluster. One sync of the parent creates every child.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: bootstrap
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/your-org/your-gitops-repo.git
    targetRevision: HEAD
    path: apps
  destination:
    server: https://kubernetes.default.svc
    namespace: argocd

The parent and its children all appear in Argo CD > Applications as ordinary Applications. The parent reaches Synced as soon as the child manifests exist, while the children stay OutOfSync until you sync them. Sync the whole set from the dashboard, where the out-of-sync children are already preselected.

Restrict who can push to the parent repository

An app of apps can create Applications in any project, which is an administrator-level capability. Give push access to the parent repository only to administrators.

To review a GitOps rollout with our team, contact us.