GitOps Repository Structure Design: Combining Helm and Kustomize, the Apps-in-App Pattern
In GitOps, repository structure is not merely a matter of file placement. How chart versions are managed, how configuration is separated by cluster, and how ArgoCD Applications themselves are managed declaratively are all reflected in the repository structure. This article covers a design for managing a cluster completely declaratively through a Helm + Kustomize combination and the Apps-in-App pattern.
Cluster Management: GitOps for Cluster Installation Too
Section titled “Cluster Management: GitOps for Cluster Installation Too”Core principles:
- Use Argo CD to configure every component required for cluster installation.
- Manage installation manifests in a Git repository.
- Perform installation through ArgoCD application sync.
- Do not install directly on the cluster with
kubectl apply: manual installations leave no history and are difficult to recover.
Git Manifests Structure: Combining Helm and Kustomize
Section titled “Git Manifests Structure: Combining Helm and Kustomize”Structure overview:
- Manage Helm charts in version-specific folders: rather than using a Helm repository, manage chart source directly in Git. When a version is needed, copy the folder to freeze that chart.
- Kustomize runs Helm templates: Argo CD first runs
kustomize build, and Kustomize invokeshelm template. - Put cluster-specific configuration in Kustomize
values.yaml: leave the base chart unchanged and keep only the differing settings for each cluster in overlay values. - Include the
commonfolder as a base: place resources shared by every component, such as TLS certificates, incommonand reference it as a Kustomize base.
ArgoCD Apps-in-App: Manage Applications Themselves in Git
Section titled “ArgoCD Apps-in-App: Manage Applications Themselves in Git”
Apps-in-App pattern:
- ArgoCD Applications can be created through the UI or CLI, but use Apps-in-App to manage the Applications themselves in a Git repository.
argocd-app-initis responsible for creating the other ArgoCD Applications.- This makes ArgoCD Applications quick to recover: syncing only
argocd-app-initautomatically creates the remaining Applications.
Deploy Repository Structure
Section titled “Deploy Repository Structure”Repository for Cluster Deployment
Section titled “Repository for Cluster Deployment”Directoryplatform-cluster-deploy/
Directorybase/
Directoryapps/
Directorypython-backend-v1.0.0/
- …
Directoryspringboot-backend-v1.0.0/
- …
Directoryspringboot-module-v1.0.0/
- …
Directoryjobs/
Directoryjob-v1.0.0/
- …
Directorypvcs/
Directorypvc-v1.0.0/
- …
Directorytemplate/
Directoryproject/
Directoryapps/
- …
Directoryjobs/
- …
Directorypvcs/
- …
Directoryprod-cluster/
Directoryproject-a/
Directoryapps/
- …
Directoryjobs/
- …
Directorypvcs/
- …
Structural principles:
- The
basefolder manages chart files and organizes folders by chart version. - The
templatefolder is configured to use a specific (final) version frombaseand is used for the actual deployment files. - Cluster-specific folders distinguish the clusters being deployed to.
- Organize folders in the form cluster - project - apps/pvcs/jobs.
- Keep the subdirectory structures of the cluster and
templatefolders aligned to prevent relative-path errors.
Cluster Initialize Repository
Section titled “Cluster Initialize Repository”Directoryplatform-cluster-init/
Directorybase/
Directoryargo/argo-workflows-v0.8.1/
- …
Directoryargocd/argo-cd-v3.26.5/
- …
Directorygitea/gitea-v4.1.1/
- …
Directoryharbor/harbor-v1.7.3/
- …
Directorycommon/
- …
Directoryprod-cluster/
Directoryargo/argo-workflows-v0.8.1/
- …
Directoryargocd/argo-cd-v3.26.5/
- …
Directorygitea/gitea-v4.1.1/
- …
Directoryharbor/harbor-v1.7.3/
- …
Directorycommon/
- …
Role of the Initialize Repository:
- Deploy the CI/CD tools and shared resources needed for initial cluster configuration.
- The
basefolder is managed by chart version, while cluster-specific folders select the charts to deploy to their respective clusters.
Deployment Flow
Section titled “Deployment Flow”This repository structure addresses chart version freezing, separation of cluster-specific configuration, and declarative Application management. When adding a new cluster, copy only the cluster folder and sync argocd-app-init to reproduce the entire environment.