Argocd folder structure

Tin Nguyen
4 min readMar 27, 2023

--

How to structure Argocd folder for multiple cluster and namespace by clearest way

Why Argo CD?

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes (the foundation of OpenShift). It is efficient, well supported, and well documented.

  • Application definitions, configurations, and environments should be declarative and version controlled.
  • Application deployment and lifecycle management should be automated, auditable, and easy to understand.

Argocd architecture:

Components:

API Server:

  • The API server is a gRPC/REST server which exposes the API consumed by the Web UI, CLI, and CI/CD systems. It has the following responsibilities:
  • application management and status reporting
  • invoking of application operations (e.g. sync, rollback, user-defined actions)
  • repository and cluster credential management (stored as K8s secrets)
  • authentication and auth delegation to external identity providers
  • RBAC enforcement
  • listener/forwarder for Git webhook events

Repository Server:

The repository server is an internal service which maintains a local cache of the Git repository holding the application manifests. It is responsible for generating and returning the Kubernetes manifests when provided the following inputs:

  • repository URL
  • revision (commit, tag, branch)
  • application path
  • template specific settings: parameters, helm values.yaml

Application Controller:

  • The application controller is a Kubernetes controller which continuously monitors running applications and compares the current, live state against the desired target state (as specified in the repo). It detects OutOfSync application state and optionally takes corrective action. It is responsible for invoking any user-defined hooks for lifecycle events (PreSync, Sync, PostSync)

How to organize folder structure for multiple clusters and namespaces

Argocd folder structure
  • Level 1: Cluster name
  • Level 2: Include all your namespaces inside a cluster
  • Level 3: All applications helm chart inside a namespace

ArgoCD tool will discovery your folder structure and deploy all of application into right cluster and namespace. How to config argocd like that?

Step by step to get there

Deploy argocd helm chart by terragrunt

Use terragrunt to deploy Argo CD helm chart

After that you have an argocd application inside your k8s cluster, then deploy argocd bootstrap applicationset

Use terragrunt to deploy Argo CD bootstrap applicationset

Let’s explore root/bootstrap:

Bootstrap applicationset helm chart
  • argocd-applicationset.yaml: will deploy bootstrap config
  • applicationset.yaml: will loop and create all cluster applicationsets

Result:

Then argocd_config applicationset will exec to folder root/argocd and deploy two folder:

  • configs
  • secrets

Result:

Continuous explore folder secret:

Argocd will exec and deploy all of folder under secrets folder, result:

Inside configs folder we have:

Important note:

We have 3 types of applicationSet.generators:

  • List
  • Git will match with repositories inside secrets folder
- git:
repoURL: '{{- $.Values.root.source.repoURL }}'
revision: '{{- $.Values.root.source.targetRevision }}'
directories:
- path: "{{- $paths }}/**/*"
- path: "**/_exclude/*"
exclude: true
- path: "root"
exclude: true
  • Cluster will match with above cluster by label inside secrets folder
- clusters:
selector:
matchLabels:
argocd.argoproj.io/secret-type: cluster
cluster-name: '{{ `{{path[0]}}` }}'

and use by

destination:
server: '{{ `{{server}}` }}'
namespace: '{{ `{{path[1]}}` }}'

{{path[0]}} is level 1 (cluster level)
{{path[1]}} is level 2 (namespace level)

--

--