[Argocd] Using Helm chart while using my values.yaml
I have been using argocd for a while and I used to put the templates in the repo which is really exhausting because open sources change their own version a lot and we need to change our version to catch up the state of the art asap.
So I was tired of copy pasting the templates and tried to find a better option, and after a while I have noticed that a lot of engineer are using the argocd and the helm chart differently from me.
https://github.com/argoproj/argo-cd/issues/2789
Helm chart + values files from Git · Issue #2789 · argoproj/argo-cd
Hello everyone, we are trying to migrate our CD processes to ArgoCD and faced an issue where I really need some input. (Checked the official documentation and threads here but seems like there is n...
github.com
The above links shows how to use the helm chart and the values properly, I will explain the details with the yaml file
first of all I will be using the app of apps pattern to manage the open sources on the kubernetes cluster.
https://argo-cd.readthedocs.io/en/stable/operator-manual/cluster-bootstrapping/
Cluster Bootstrapping - Argo CD - Declarative GitOps CD for Kubernetes
Cluster Bootstrapping This guide is for operators who have already installed Argo CD, and have a new cluster and are looking to install many apps in that cluster. There's no one particular pattern to solve this problem, e.g. you could write a script to cre
argo-cd.readthedocs.io
if you do not know about the pattern you can check it on the above link.
now I will create a folder in my app
first we will like to look on the values file for apps which is "values.yaml"
app:
keycloak:
namespace: keycloak
targetRevision: 18.6.1
chartName: keycloak
repoURL: https://charts.bitnami.com/bitnami
eck-operator-crds:
namespace: elasticsearch
targetRevision: 2.11.1
chartName: eck-operator-crds
repoURL: https://helm.elastic.co
eck-operator:
namespace: elasticsearch
targetRevision: 2.11.1
chartName: eck-operator
repoURL: https://helm.elastic.co
spec:
destination:
server: https://kubernetes.default.svc
app:
myRepo: https://github.com/myorg/myrepo
chartValue: kubernetes/charts/charts-template
path: kubernetes/charts/charts-bitnami
valueFilePath: values/values-demo.yaml
as you can see in the image I am planning to get the eck operator and the keycloak each version is 18.6.1 and 2.11.1
these are just values so if you want you can edit it your way : )
now for the tricky part as you have noticed there is an application.yaml file in the first image which is the essential stuff for it.
{{- range $key,$val := .Values.app }}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: {{ $key }}
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
destination:
server: https://kubernetes.default.svc
namespace: {{ $val.namespace }}
project: default
sources:
- repoURL: {{ $.Values.spec.app.myRepo}}
targetRevision: HEAD
ref: myRepo
- repoURL: {{ $val.repoURL}}
targetRevision: {{ $val.targetRevision }}
chart: {{ $val.chartName }}
helm:
valueFiles:
- $myRepo/{{ $.Values.spec.app.chartValue}}/{{ $val.chartName }}/{{ $.Values.spec.app.valueFilePath }}
{{- end }}
if it is your first time with helm chart I recommend you to check the syntaxs before checking the templates.
the application.yaml is a template which is a special frame which will get the values from values. yaml
in the first row you will notice that I will get the values from the app section in the values.yaml and devide it into val and key.
so for example key will be "keycloak, eck-operator, eck-operator-crd" so there will be 3 app and each will named by them.
and at line 7 you will notice that I will be using the apps configs like the namespace, repoURL, and chartName
the namespace will be filled in which each value.
And the most important part
When you look in line 15 there is a attribute name source which will the source of the applications yaml.
In the first source I will get my repo "github.com/myorg/myrepo" and name it as myRepo ( ref ) and targeting the HEAD.
And the second source is the remote helm charts like bitnami/keycloak, elastic/eck-operator.
so when the values get in.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: eck-operator-crds
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
destination:
server: https://kubernetes.default.svc
namespace: elasticsearch
project: default
sources:
- repoURL: https://github.com/myorg/myrepo
targetRevision: HEAD
ref: myRepo
- repoURL: https://helm.elastic.co
targetRevision: 2.11.1
chart: eck-operator-crds
helm:
valueFiles:
- $myRepo/kubernetes/charts/charts-template/eck-operator-crds/values/values-demo.yaml
which is pretty awesome.
So if you are considering to use helm chart and argocd to use open source like prometheus then I highly recommend doing these kind of stuffs.
1. you can control versions
2. do not need to copy paste the templates you can just use the official ones
3. manage the whole apps with app of apps and lighten your repo
Well that`s all :) hope you enjoy your day.