Setup
We'll create templates for a set of ArgoCD applications using the DRY (Don't Repeat Yourself) approach with Helm charts:
.
|-- app-of-apps
| |-- Chart.yaml
| |-- templates
| | |-- _application.yaml
| | `-- application.yaml
| `-- values.yaml
|-- ui
`-- catalog
...
The _application.yaml
is a template file which will be used to dynamically create applications based on a list of component names:
{{- define "application" -}}
{{- $root:= . }}
{{- range $application := .Values.applications}}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: {{ $application.name }}
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
labels:
app.kubernetes.io/created-by: eks-workshop
spec:
project: default
destination:
server: {{ $root.Values.spec.destination.server }}
namespace: {{ $application.name }}
source:
repoURL: {{ $root.Values.spec.source.repoURL }}
targetRevision: {{ $root.Values.spec.source.targetRevision }}
path: {{ $application.name }}
syncPolicy:
syncOptions:
- CreateNamespace=true
automated:
prune: true
selfHeal: true
{{- end -}}
{{- end -}}
The values.yaml
file specifies a list of components for which ArgoCD applications will be generated, as well as configuration related to the Git repository that will be common across all applications:
spec:
destination:
server: https://kubernetes.default.svc
source:
repoURL: ${GITOPS_REPO_URL_ARGOCD}
targetRevision: main
applications:
- name: carts
- name: catalog
- name: checkout
- name: orders
- name: ui
First, let's copy this foundational App of Apps configuration to our Git directory:
Now, let's commit and push these changes to the Git repository:
Next, we need to create a new Argo CD Application to implement the App of Apps pattern. While doing this, we'll enable ArgoCD to automatically synchronize the state in the cluster with the configuration in the Git repository using the --sync-policy automated
flag:
application 'apps' created
Open the Argo CD UI and navigate to the main "Applications" page. Our App of Apps configuration has been deployed and synced, but except for the UI component, all of the workload apps are marked as "Unknown".
We will deploy the configurations for the workloads in the next step.