TExcelTAD
Home › GitOps: Argo CD & Flux › Repository Layouts

Repository Layouts

There is no single correct GitOps layout, but there are a few that work and a few that hurt. The decision is about three questions: how many repositories, how environments are separated, and how the agent finds what to deploy.

How many repositories

Layout Shape Good for Watch out for
App + config split (this course) linkly (code) and linkly-deploy (config) most teams; clean deploy history a second repo per app, unless config repos are shared
Monorepo for config one platform-deploy repo with every app and cluster platform teams, small orgs access control is per repo in most Git hosts (CODEOWNERS helps), large repos slow agents down
Repo per team team-a-deploy, team-b-deploy + a platform repo for shared infrastructure many teams, multi-tenancy consistent conventions across repos
Config inside the app repo deploy/ folder next to the code one small service every code commit wakes the agent; CI tag bumps loop back into CI

Most organisations end up with a platform repository (cluster add-ons: Gateway controller, cert-manager, monitoring, policies) plus app config repositories, with the agent's own bootstrap objects in the platform repo.

Environments: folders, not branches

A tempting design is one branch per environment (staging, production), promoting by merging. It goes wrong in predictable ways:

  • branches diverge: hotfixes made directly on production never get back to staging, and the next merge brings surprises;
  • a merge carries everything that changed, not just the one version you meant to promote;
  • the diff "what differs between staging and production?" is a branch comparison, not a file you can read.

With folders on one branch, each environment is a directory, the differences between environments are the files themselves, and promotion is a small, reviewable commit. Both Argo CD and Flux docs recommend this; branches are still fine for short-lived pull-request branches.

A Flux-style monorepo

The Flux docs describe a layout with three top-level folders that suits any agent:

bash · try it yourself
mkdir -p fleet && cd fleet
mkdir -p infrastructure/gateway apps/base/linkly apps/staging apps/production clusters/staging clusters/production
cat > infrastructure/gateway/gateway.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata: {name: public, namespace: gateway-system}
spec:
  gatewayClassName: shared
  listeners: [{name: http, protocol: HTTP, port: 80, allowedRoutes: {namespaces: {from: All}}}]
EOF
printf 'resources: [gateway.yaml]\n' > infrastructure/gateway/kustomization.yaml
cat > apps/base/linkly/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: linkly}
spec:
  replicas: 2
  selector: {matchLabels: {app.kubernetes.io/name: linkly}}
  template:
    metadata: {labels: {app.kubernetes.io/name: linkly}}
    spec:
      containers: [{name: linkly, image: ghcr.io/acme/linkly:1.4.0}]
EOF
printf 'resources: [deployment.yaml]\n' > apps/base/linkly/kustomization.yaml
for env in staging production; do
  if [ $env = staging ]; then ns=linkly-staging tag=1.5.0-rc.1; else ns=linkly-prod tag=1.4.0; fi
  cat > apps/$env/kustomization.yaml <<EOF
namespace: $ns
resources: [../base/linkly]
images: [{name: ghcr.io/acme/linkly, newTag: $tag}]
EOF
done
tree --noreport
for env in staging production; do
  printf '%-11s ' "$env:"
  kustomize build apps/$env | yq '.metadata.namespace + " " + .spec.template.spec.containers[0].image'
done
kustomize build infrastructure/gateway | kubeconform -strict -summary -
.
├── apps
│   ├── base
│   │   └── linkly
│   │       ├── deployment.yaml
│   │       └── kustomization.yaml
│   ├── production
│   │   └── kustomization.yaml
│   └── staging
│       └── kustomization.yaml
├── clusters
│   ├── production
│   └── staging
└── infrastructure
    └── gateway
        ├── gateway.yaml
        └── kustomization.yaml
staging:    linkly-staging ghcr.io/acme/linkly:1.5.0-rc.1
production: linkly-prod ghcr.io/acme/linkly:1.4.0
Summary: 1 resource found parsing stdin - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
  • infrastructure/ holds cluster add-ons, reconciled first (an app's HTTPRoute needs the Gateway API CRDs and a Gateway).
  • apps/base is shared; apps/<env> are thin overlays (see Bases & Overlays).
  • clusters/<name>/ is the entry point for the agent on that cluster: Flux Kustomization objects (or Argo CD Applications) that point at infrastructure/ and apps/<env>, with the dependency between them. Adding a cluster means adding one folder.

How the agent finds things

Mechanism Argo CD Flux
one object per app and environment Application Kustomization or HelmRelease
an object that creates the others app of apps the flux-system Kustomization reading clusters/<name>/
generate many from a pattern ApplicationSet (Git directories, clusters, lists) one Kustomization per folder, or Flux Operator's ResourceSets

Naming and ownership conventions that pay off

  • Folder names map to namespaces by one fixed rule (apps/staging → linkly-staging, apps/production → linkly-prod), so generators can derive one from the other.
  • A CODEOWNERS file maps apps/production/ to the people who approve production changes.
  • Everything that is cluster-scoped (CRDs, ClusterRoles, Namespaces) lives under infrastructure/, owned by the platform team; app folders contain only namespaced objects. Argo CD Projects and Flux tenants can then enforce that split (Projects & Access Control).

Test yourself

Why do GitOps guides recommend folders per environment over branches per environment?

  1. Git limits the number of branches
  2. Branches diverge and merges promote everything at once; folders keep differences visible and promotion small
  3. Agents can only read the main branch
  4. Folders are faster to clone

In the Flux-style monorepo, what is the role of clusters/production/?

  1. It holds the production Deployments
  2. It is the agent's entry point: objects that point at infrastructure/ and apps/production
  3. It stores kubeconfigs
  4. It is the Helm chart