GitOps using ArgoCD: App of apps pattern

What is GitOps?

GitOps presents an idea of reconciliation from the single source of truth: Git to paint the definition in Git to the external entity. Everything which is Git holding should represent the state of the entity at all times.

GitOps made its way to popular kids with the rise of the Cloud and specifically Kubernetes and ArgoCD. An external entity is the most often Kubernetes and ArgoCD holds the responsibility of the reconciliation from the Git to the Kubernetes cluster.

ArgoCD

ArgoCD is a graduate project from CNCF. Here's a little sneak peek of the end result of creating the ArgoCD app of apps pattern.

ArgoCD applications in the UI.

ArgoCD lets you define the application resource directly from the YAML - an alternative is to use ArgoCD UI.

If you are planning to use the ArgoCD to deploy multiple applications or even multiple environments - An application must be created specifying the parameters for every application. It works like this:

The application can fetch from the repo URL on a specific branch and deploy the resources to Kubernetes. This process can be automatic. Sync can be done automatically or manually.

Example of the Application manifest.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: qdnqn-nginx
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: nginx
    server: {{ .Values.spec.destination.server }}
  project: qdnqn
  source:
    path: argocd/charts/nginx
    repoURL: https://github.com/qdnqn/qdnqn-gitops-argocd.git
    targetRevision: HEAD
    helm:
      valueFiles:
        - values.yaml

This application will track the repoURL on the path of targetRevision (branch, commit, or tag).

ArgoCD can deploy applications defined using:

  • Helm
  • Kustomize
  • Plain YAML
  • Any other custom config management tool (See more)

That means that we also can define Custom Resources used by Argo to tweak the Argo itself. Of course, proper permissions and configuration need to be done to the application handling Argo manifests.

ArgoCD app-of-apps pattern

Consequently it enables the pattern itself app of apps.

kind: Application
metadata:
  name: app-of-apps
  namespace: argocd
spec:
  project: qdnqn
  source:
    repoURL: https://github.com/qdnqn/qdnqn-gitops-argocd.git
    targetRevision: HEAD
    path: argocd/apps
  destination:
    server: https://kubernetes.default.svc

app-of-apps.yaml

This application will reference the project which gives this application all permissions.

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: qdnqn
  namespace: argocd
spec:
  description: App of apps qdnqn GitOps demo example.
  destinations:
    - namespace: '*'
      server: '*'
  clusterResourceWhitelist:
    - group: '*'
      kind: '*'
  namespaceResourceWhitelist:
    - group: '*'
      kind: '*'
  sourceRepos:
    - '*'

project.yaml

Application app-of-apps will deploy all other applications defined in the chart apps and deploy them to the Kubernetes cluster. ArgoCD will pick those manifests and create an Application in the ArgoCD itself.

All new applications will be visible in the ArgoCD UI and they can be deployed to the cluster.

After syncing the qdnqn-nginx application, ArgoCD will deploy helm chart to the cluster and nginx will be live.


This was quick introduction to the app of apps pattern using ArgoCD. It lays out foundation for the next article where we will discuss how to use ArgoCD for the multi environment deployments scenario. Stay tuned.

Complete example is available in the repo. The repo contains scenario of two child applications which deploy the nginx on the Kubernetes.

GitHub - qdnqn/qdnqn-gitops-argocd: GitOps implementation using ArgoCD examples
GitOps implementation using ArgoCD examples. Contribute to qdnqn/qdnqn-gitops-argocd development by creating an account on GitHub.