gitlabkubernetes-helmargocdjfrog-container-registry

How Do I Deploy Multiple Apps via ArgoCD in Kubernetes using Single Helm Chart


I have requirement to deploy multiple apps in Kubernetes using single(common) helm chart, and app deployment will be happen via ArgoCD. Have created Helm charts and pushed it in Jfrog OCI based registries and the application value files(value.yaml) are present in gitlab repositories.

Trying to deploy ArgoCD app 'argocd-app' with gitlab pipeline, which will deploy main Argocd application and it'll keep detecting whatever cahnges/new additions of value files happened in the gitlab repositories and accordingly Argocd will deploy/change applications in k8s.

Using below mentioned gitlab pipleline file, but it's deploying only 'argocd-apps' with code present in approach1.yaml file.

Request your assistance here on what changes I need do in this pipeline file so that 'argocd-app' app will check for the other application value.yaml files present in the gitlab repo "argocd-apps/prm-helmchart/value_files" and will auto deploy. Or You can suggest entirely alternate way to achieve above mentioned requirement.

.gitlab-ci.yml file:

stages:
  - prepare
  - deploy

prepare:
  stage: prepare
  script:
    - git clone https://$CI_GITLAB_USER:$CI_GITLAB_TOKEN@gitlab.com/gitlab1511220/argocd-apps.git
    - cp -r argocd-apps/prm-helmchart/value_files .
  artifacts:
    paths:
      - argocd-apps/prm-helmchart/approach1.yaml

deploy:
  stage: deploy
  image: google/cloud-sdk:latest
  script:
    - gcloud container clusters get-credentials my-gke-cluster1 --zone australia-southeast1-a --project my-project-v1
    #- helm registry login $JFROG_DOMAIN -u $JFROG_USER -p $JFROG_PASSWORD
    - |
      cat <<EOF | kubectl apply -f -
      apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: argocd-apps
        namespace: argocd
      spec:
        project: default
        source:
          repoURL: 'cstmimgjfrog.jfrog.io'
          chart: 'helm-oci-local/oci'
          targetRevision: '0.1.0'
          helm: 
            valueFiles:
              - value_files/approach1.yaml
        destination:
          server: 'https://kubernetes.default.svc'
          namespace: py-apps
        syncPolicy:
          automated:
            prune: true
            selfHeal: true
      EOF
  dependencies:
    - prepare

You can suggest required modifications Or alternate way can be suggested to achieve above mentioned requirement. (i.e. Requirement: To deploy multiple apps in Kubernetes using single(common) helm chart, and app deployment will be happen via ArgoCD, vave created Helm charts and pushed it in Jfrog OCI based registries)


Solution

  • I worked further on the above requirement and here is the code that finally worked to get through.

    There is no need to create the gitlab pipeline. Simply apply the given argocd manifest file to get app deployed in k8s and then app status can be seen in the Argocd console.

    Our Helm OCI is stored in jfrog and apps values files are stored in gitlab repo.

    We need to create the separate manifest file for each application and specify the respective application valueFiles under "sources: >> helm: >> valueFiles:"

    This way we can use common Helm chart for multiple applications.

    argocd-manifest-app1.yaml

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: application-1
      namespace: argocd
    spec:
      project: default
      sources:
        - repoURL: 'cstmimgjfrog.jfrog.io'
          chart: 'helm-oci-local/oci'
          targetRevision: '0.1.0'
          helm: 
            valueFiles:
              - $values/app-value-files/values-app1.yaml
              #Note: keep '$values' as it is and after that mention values file path from below gitlab repository
        - repoURL: https://gitlab.com/gitlab1122337/argocd.git
          targetRevision: main
          ref: values
      destination:
        server: 'https://kubernetes.default.svc'
        namespace: my-apps
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

    argocd-manifest-app2.yaml

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: application-2
      namespace: argocd
    spec:
      project: default
      sources:
        - repoURL: 'cstmimgjfrog.jfrog.io'
          chart: 'helm-oci-local/oci'
          targetRevision: '0.1.0'
          helm: 
            valueFiles:
              - $values/app-value-files/values-app2.yaml
              #Note: keep '$values' as it is and after that mention values file path from below gitlab repository
        - repoURL: https://gitlab.com/gitlab1122337/argocd.git
          targetRevision: main
          ref: values
      destination:
        server: 'https://kubernetes.default.svc'
        namespace: my-apps
      syncPolicy:
        automated:
          prune: true
          selfHeal: true