ApplicationSets: Generate Applications from Templates
Doing More with the ApplicationSet
The whole point is varying things per cluster. Any field in the template can pull from an element key, so to make something differ between test and prod, you add a key to each element and reference it in the template.
Let's say you want one replica in test and three in prod. Add a replicas key to each element, then read it in a helm.parameters entry in the template:
cat < $HOME/web-appset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: web
namespace: argocd
spec:
generators:
- list:
elements:
- cluster: test
url: https://test-api.example:6443
replicas: "1"
- cluster: prod
url: https://prod-api.example:6443
replicas: "3"
template:
metadata:
name: 'web-{{cluster}}'
spec:
project: default
source:
repoURL: $HELM_REPO_URL
targetRevision: 0.2.0
chart: web
helm:
# {{replicas}} pulls from each element. test gets "1", prod gets "3".
parameters:
- name: replicaCount
value: '{{replicas}}'
destination:
server: '{{url}}'
namespace: 'web-{{cluster}}'
syncPolicy:
syncOptions:
- CreateNamespace=true
automated:
prune: true
selfHeal: true
EOF
Now the two generated Applications differ in one more field:
web-test: serverhttps://test-api.example:6443, namespaceweb-test,replicaCount1.web-prod: serverhttps://prod-api.example:6443, namespaceweb-prod,replicaCount3.
The element is a bag of key-value pairs, and you decide what each key drives. replicas here, but it could just as well feed a path, an image tag, a target revision, or any other template field. Keys you don't reference in the template are ignored, so there's no harm in carrying extra ones.
GitOps the Hard Way, with Argo CD
Build Real GitOps Pipelines From Empty Clusters to Automated DeploysEnroll now to unlock all content and receive all future updates for free.
