0

I have a git repo, which hosts YAML manifests for all of my applications running on Kubernetes.
The directory structure is as follows:

- namespace_1
  - app_1
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml

  - app_2
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml

.
.
.

- namespace_n
  - app_n_1
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml

  - app_n_2
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml



  • I am planning to use ARGOCD for the deployment of these apps.
  • I was going through the documentation and deployed a testing project to get hands-on.
  • But I am not sure, how I can import all of my applications to ARGOCD, as separate applications. As I already have well-defined YAMLs, in a proper directory structure.
  • I was able to add applications one by one manually using UI, but is there an import tool or method, which will help me accomplish my objective?
kadamb
  • 1,532
  • 3
  • 29
  • 55

1 Answers1

0

One way to accomplish this is to use the app-of-apps pattern in which you have one "root" application which is only responsible for setting up the other applications.

This is easy when using Helm, which allows you to loop over a folder. A soultion could then be to have the following structure:

-app-of-apps
    - app-of-app
        -templates
            -applications.yaml
        values.yaml
- apps
  - app_1
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml

  - app_2
    - deployment.yaml
    - service.yaml
    - ingress.yaml
    - configmap.yaml

in the applications.yaml you could do something like:

{{- range $k, $v := .Values.applications }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
    name: ...
    namespace: ...
spec:
    project: ...
    source:
        helm:
          valueFiles:
             values.yaml
        repoURL: {{ $.Values.spec.source.repoURL }}
        targetRevision: {{ $.Values.spec.source.targetRevision}}
        path: {{ $v.path }}
    destination:
        server: "https://kubernetes.default.svc"
        namespace: ...
    syncPolicy:
        automated:
            selfHeal: true
            prune: true
        syncOptions:
        - CreateNamespace=true
---
{{- end }}

Your values.yaml in the app-of-apps folder could then look like this:

spec:
  source:
    repoURL: ...
applications:
  app_1:
    name: app_1
    path: apps/app_1
  app_2:
    name: app_2
    path: apps/app_1
  ...

In the applications.yaml file, {{- range $k, $v := .Values.applications }} will loop through the applications listed in the app-of-apps/app-of-app/values.yaml under applications and set them up.

Haukland
  • 677
  • 8
  • 25