6.2 Application Sets
With the ApplicationSet ArgoCD adds support for managing ArgoCD Application across a large number of clusters and environments. Plus it adds the capability of managing multitenant Kubernetes clusters.
ApplicationSets are defined through Custom Resource Definition and are processed by the ApplicationSet controller.
The ApplicationSet provides following features
- The ability to use a single Kubernetes manifest to target multiple Kubernetes clusters with Argo CD
- The ability to use a single Kubernetes manifest to deploy multiple applications from one or multiple Git repositories with Argo CD
- Improved support for monorepos: in the context of Argo CD, a monorepo is multiple Argo CD Application resources defined within a single Git repository
- Within multitenant clusters, improves the ability of individual cluster tenants to deploy applications using Argo CD (without needing to involve privileged cluster administrators in enabling the destination clusters/namespaces)
A list of parameters, which come from so called generators , render the ArgoCD Application Template to create a list of Applications.
The ApplicationSet resources work in a similar way as Helm templates do. You can define a set of placeholders {{placeholder}}
which then are replaced with the actual value during the processing of the ApplicationSet.
Task 6.2.1: Create an ApplicationSet
First delete the Ingress resource under ~/argocd-training-examples/example-app/ingress.yaml
For better understanding we create our first ApplicationSet. Create a yaml file with the following content under ~/argocd-training-examples/application-set/simple-example/application-set.yaml
and replace the <username>
placeholder with your actual username.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: application-set-<username>
spec:
generators:
- list:
elements:
- cluster: dev-cluster
url: https://kubernetes.default.svc
env: dev
traininguser: <username>
- cluster: prod-cluster
url: https://kubernetes.default.svc
env: prod
traininguser: <username>
template:
metadata:
name: '{{cluster}}-as-example-{{traininguser}}'
spec:
project: default
source:
repoURL: 'https://gitea.training.cluster.acend.ch/{{traininguser}}/argocd-training-examples.git'
targetRevision: HEAD
path: example-app
destination:
server: '{{url}}'
namespace: '{{traininguser}}-{{env}}'
syncPolicy:
automated:
prune: true
selfHeal: true
Now let’s make sure to apply this to the cluster. But wait, we can either directly apply the yaml or we can create an ArgoCD Application just containing the ApplicationSet. Let’s go the GitOps path:
git add .
git commit -m "Add ApplicationSet"
git push origin main
And now create the ArgoCD Application, which references the ApplicationSet definition:
argocd app create argo-appset-$USER --repo https://gitea.training.cluster.acend.ch/$USER/argocd-training-examples.git --path 'application-set/simple-example' --dest-server https://kubernetes.default.svc --sync-policy auto --dest-namespace argocd
Note
Please notice thedest-namespace
, ApplicationSets needs to be deployed within the argocd
namespaceYou should now be able to see three ArgoCD Applications postfixed with your <username>
:
argo-appset-<username>
The application containing your ApplicationSet.dev-cluster-as-example-<username>
ArgoCD Application for the fist set of key value pairs:dev
prod-cluster-as-example-<username>
ArgoCD Application for the second set of key value pairs:prod
Generators
The generators (generators
spec in the ApplicationSet yaml) are the building block on how to specify the list of parameters that will be used to generate the Applications.
There are several built in generators. Check out the official documentation
for more information.
You have even the possibility to combine multiple generators together using the Matrix generator.
Matrix generator
The Matrix generator combines the parameters generated by two child generators, iterating through every combination of each generator’s generated parameters.
- SCM Provider Generator + Cluster Generator: Scanning the repositories of a GitHub organization for application resources, and targeting those resources to all available clusters.
- Git File Generator + List Generator: Providing a list of applicatations to deploy via configuration files, with optional configuration options, and deploying them to a fixed list of clusters.
- Git Directory Generator + Cluster Decision Resource Generator: Locate application resources contained within folders of a Git repository, and deploy them to a list of clusters provided via an external custom resource.
- And so on…
Task 6.2.2: Matrix Example ApplicationSet
In this lab section we’re going to create an ApplicationSet for an multi-environment.
- Multiple Clusters
- Multiple Applications out of a git directory
Since we don’t have multiple clusters configured in our ArgoCD Cluster, we’re going to use the list generator instead of the cluster generator, with two entries dev
and prod
both pointing to the local cluster at https://kubernetes.default.svc
.
The list generator generating values for two clusters dev
and prod
looks like this:
- list:
elements:
- cluster: dev
url: https://kubernetes.default.svc
- cluster: prod
url: https://kubernetes.default.svc
The git generator which for the Applications will therefore look like this:
- git:
repoURL: https://github.com/acend/argocd-training-examples.git
revision: HEAD
directories:
- path: application-set/matrix-git-example/*
Both generators generate two sets of parameters
cluster | url | path | path.basename | |
---|---|---|---|---|
dev | https://kubernetes.default.svc | application-set/matrix-git-example/application1 | application1 | |
dev | https://kubernetes.default.svc | application-set/matrix-git-example/application2 | application2 | |
prod | https://kubernetes.default.svc | application-set/matrix-git-example/application1 | application1 | |
prod | https://kubernetes.default.svc | application-set/matrix-git-example/application2 | application2 |
Next let’s put everything together, create the Application Set ~/argocd-training-examples/application-set/matrix-example/matrix-example-application-set.yaml
and add the following content:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: application-set-matrix-<username>
spec:
generators:
- matrix:
generators:
- list:
elements:
- cluster: dev
url: https://kubernetes.default.svc
- cluster: prod
url: https://kubernetes.default.svc
- git:
repoURL: https://github.com/acend/argocd-training-examples.git
revision: HEAD
directories:
- path: application-set/matrix-git-example/*
template:
metadata:
name: 'as-matrix-<username>-{{path.basename}}-{{cluster}}'
spec:
project: default
source:
repoURL: 'https://gitea.training.cluster.acend.ch/<username>/argocd-training-examples.git'
targetRevision: HEAD
path: '{{path}}'
destination:
server: https://kubernetes.default.svc
namespace: '<username>-{{cluster}}'
Make sure to replace all <username>
occurrences with your username.
Push the changes to your git repository.
git add .
git commit -m "Add Matrix Example"
git push origin main
And let’s create an ArgoCD Application containing the Matrix ApplicationSet with the following command:
argocd app create argo-appset-matrix-$USER --repo https://gitea.training.cluster.acend.ch/$USER/argocd-training-examples.git --path 'application-set/matrix-example' --dest-server https://kubernetes.default.svc --sync-policy auto --dest-namespace argocd
Next check the ArgoCD web ui, you should see the 4 generated ArgoCD applications together with the ArgoCD Application, which contains the ApplicationSet itself.
Task 6.2.3: Delete the Application
Delete the two applications (argo-appset-$USER
and argo-appset-matrix-$USER
) after you’ve explored the Argo CD Resources and the managed Kubernetes resources.
Hint
argocd app delete argo-appset-$USER
argocd app delete argo-appset-matrix-$USER