Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Argocd: ApplicationSet

Back


ApplicationSet


Common Commands

Command Description
kubectl get appset -n argocd List ApplicationSets in the Argo CD namespace.
kubectl get appset <name> -n argocd View one ApplicationSet.
kubectl describe appset <name> -n argocd Show detailed status, events, and troubleshooting information.
kubectl delete appset <name> -n argocd Delete an ApplicationSet. Usually also removes generated Applications.
kubectl get applications -n argocd List Applications generated by the ApplicationSet.
kubectl logs -n argocd deploy/argocd-applicationset-controller Check ApplicationSet controller logs.

Core Components


Generator


List generator

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
    - list:
      elements:
        - cluster: engineering-prod-1
          url: https://1.2.3.4
        - cluster: engineering-prod-2
          url: https://2.4.6.8
template:
  metadata:
    name: "-guestbook"
  spec:
    destination:
      server: ""
      namespace: guestbook
    source:
      repoURL: https://github.com/argoproj/argocd-example-apps.git
      targetRevision: HEAD
      path: guestbook/

Cluster Generator

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
    - cluster:
        selector: # the cluater with target labels
          matchLabels:
            env: staging
        values: # additional values
          revision: HEAD
    - cluster:
        selector: # the cluater with target labels
          matchLabels:
            env: production
        values: # additional values
          revision: stable

  template:
    metadata:
      name: "-guestbook"
    spec:
      destination:
        server: ""
        namespace: guestbook
      source:
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: ""
        path: guestbook

Git Generator


parameters are:


exclude feature


Matrix generator: The Matrix generator may be used to combine the generated parameters of two separate generators. • Merge generator: The Merge generator may be used to merge the generated parameters of two or more generators. Additional generators can override the values of the base generator. • SCM Provider generator: The SCM Provider generator uses the API of an SCM provider (eg GitHub) to automatically discover repositories within an organization. • Pull Request generator: The Pull Request generator uses the API of an SCMaaS provider (eg GitHub) to automatically discover open pull requests within an repository. • Cluster Decision Resource generator: The Cluster Decision Resource generator is used to interface with Kubernetes custom resources that use custom resourcespecific logic to decide which set of Argo CD clusters to deploy to.


Lab: Deploy Applications with ApplicationSet

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet

metadata:
  name: guestbook-appset
  namespace: argocd

spec:
  goTemplate: true
  goTemplateOptions:
    - missingkey=error

  generators:
    - list:
        elements:
          - env: dev
            namespace: guestbook-dev
          - env: prod
            namespace: guestbook-prod

  template:
    metadata:
      name: "-guestbook"

    spec:
      project: default

      source:
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: HEAD
        path: guestbook

      destination:
        server: https://kubernetes.default.svc
        namespace: ""

      syncPolicy:
        syncOptions:
          - CreateNamespace=true
kubectl apply -f demo_appset.yaml
# applicationset.argoproj.io/guestbook-appset created

argocd app sync dev-guestbook
argocd app sync prod-guestbook

argocd app list
# NAME                   CLUSTER                         NAMESPACE       PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                                 PATH       TARGET
# argocd/dev-guestbook   https://kubernetes.default.svc  guestbook-dev   default  Synced  Healthy  Manual      <none>      https://github.com/argoproj/argocd-example-apps.git  guestbook  HEAD
# argocd/prod-guestbook  https://kubernetes.default.svc  guestbook-prod  default  Synced  Healthy  Manual      <none>      https://github.com/argoproj/argocd-example-apps.git  guestbook  HEAD