Skip to content

ArgoCD: Application of ApplicationSets

An application of ApplicationSets in ArgoCD is to efficiently manage and deploy similar applications or configurations across multiple clusters or namespaces. Here's a specific example to illustrate the application of ApplicationSets:

Scenario

Imagine you have a microservices architecture, and you need to deploy the same application stack to multiple namespaces within a Kubernetes cluster. Each namespace may represent a different environment, such as development, testing, and production.

ApplicationSets Implementation

1. Generator:

  • Define a generator that generates application names, namespaces, and other parameters based on a specific pattern or set of rules.
1
2
3
4
5
generators:
- list:
    elements:
    - name: my-app-{{randAlphaNum 5}}
      namespace: {{item}}

2. Template:

  • Create a template specifying the common configuration for your application. This includes the source repository, target revision, and destination settings.
template:
   metadata:
      labels:
         app.kubernetes.io/name: '{{.name}}'
   spec:
      project: default
      source:
         repoURL: 'https://github.com/example/repo'
         targetRevision: HEAD
      destination:
         namespace: '{{.namespace}}'
         server: 'https://kubernetes.default.svc'

3. ApplicationSet Manifest:

  • Apply the ApplicationSet manifest that defines the generators and template.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
   name: my-app-set
spec:
   generators:
   - list:
         elements:
         - dev
         - test
         - prod
template:
   metadata:
      labels:
      app.kubernetes.io/part-of: my-app-set
   spec:
      project: default
      source:
      repoURL: 'https://github.com/example/repo'
      targetRevision: HEAD
      destination:
      server: 'https://kubernetes.default.svc'

Result

  • ArgoCD will dynamically generate and deploy three instances of the application, each to a different namespace (dev, test, prod).
  • The common configuration specified in the template ensures consistency across all instances.
  • Changes made to the ApplicationSet manifest automatically reflect in the generated applications, allowing for easy scaling and maintenance.

Use Cases

1. Scalable Deployments:

  • Easily scale deployments across different namespaces or clusters without manually managing each application.

2. Environment Isolation:

  • Isolate configurations for different environments, ensuring separation and consistency.

3. Efficient Management:

  • Streamline the deployment of similar applications with minimal manual intervention.

ApplicationSets in ArgoCD provide a powerful mechanism for handling repetitive deployment scenarios and managing configurations at scale.