Contents

Argocd ApplicationSet helm subcharts example

/argo/argo-stacked-color-699x1024.png

In this post I will share how do I add and deploy upstream helm charts using ArgoCD ApplicationSet in my personal kubernetes server and how do I use ApplicationSet generators to automatically create ArgoCD Applications using the flexibility of the ApplicationSet controller.

Prerequisites used in this example:

  1. git repository
  2. Kubernetes and ArgoCD allready installed. (At the time of writing: kubernetes v1.24.1, ArgoCD v2.5.0)
  3. ArgoCD deployed in “argocd” namespace

I use the Git Directory Generator approach:
It creates variables based on the directory structure in your Git repository and then uses paths/subPaths as variables to use them in the ArgoCD Application template, this generator will help you to automatically create applications if you have a structure where you put every application manifests in a single directory in the same Git repository.

Repo structure:

1
2
3
4
5
6
7
8
9
<pre class="wp-block-code language-shell">```
├── applicationset.yaml
└── apps
    ├── kube-state-metrics
    │   ├── Chart.yaml
    │   └── values.yaml
    └── webapp
        ├── Chart.yaml
        └── values.yaml

applicationset.yaml file created in the root of the git repo:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: apps
spec:
  generators:
  - git:
      repoURL: https://<MY_REPO_URL>/georgios/argo.git
      revision: master
      directories:
      - path: apps/*
  template:
    metadata:
      name: '{{path.basename}}'
    spec:
      project: default
      source:
        repoURL: https://<MY_REPO_URL>/georgios/argo.git
        targetRevision: master
        path: '{{path}}'
      destination:
        server: https://kubernetes.default.svc
        namespace: '{{path.basename}}'
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true
        - Replace=true

Sample kube-state-metrics Chart.yaml file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<pre class="wp-block-code language-yaml">```
---
apiVersion: v2
name: kube-state-metrics
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "2.6.0"
dependencies:
- name: kube-state-metrics
  version: 4.21.0
  repository: https://prometheus-community.github.io/helm-charts

Values file is the common helm values file format I will not describe it further.

Create the applicationset in Argocd:
kubectl apply -f applicationset.yaml -n argocd

Once the application set is applied will search “apps” folders and deploy the applications automatically and sync with the repo for any future changes.

Using this approach if we have to update an application version I will just change the versions in Chart.yaml and argocd will take care to update the application automatically, or if we need to deploy a new application we will just need to create a new app folder create Chart.yaml file and values.yaml and once we push our changes to the repo ArgoCD will sync and deploy the new application.

Ref: Generating Applications with ApplicationSet
ArgoCD helm dependencies examples