Lab 05: Helm
Argo CD renders Helm with helm template and applies the output, it never runs helm install. No Helm release exists in the cluster (so no helm list, no lookup, no Helm rollback).
Chart in Git
mkdir helm-demo && cd helm-demo
helm create my-web-app
helm lint my-web-app
- Tweak
my-web-app/values.yaml(replicaCount: 2,image.tag: "1.25"), push to a repo
git init && git add . && git commit -m "chart"
gh repo create helm-demo --public --source=. --push
argocd app create my-web-app-helm \
--repo https://github.com/<user>/helm-demo.git \
--path my-web-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
argocd app sync my-web-app-helm
argocd app manifests my-web-app-helm
- A dir with a
Chart.yamlis detected as Helm automatically argocd app manifests= the rendered output, same ashelm template my-web-app-helm my-web-app- Release name defaults to the app name, override with
--release-name
Values
Parameter overrides:
argocd app set my-web-app-helm --helm-set replicaCount=3 --helm-set image.tag=1.26
argocd app get my-web-app-helm --show-params
argocd app sync my-web-app-helm
- These are stored on the
Application, not in Git --helm-set-stringforces a string,--helm-set-file key=pathloads a value from a file
Values files (paths relative to the chart dir):
cat > my-web-app/values-prod.yaml <<EOF
replicaCount: 5
image:
tag: "1.25"
EOF
argocd app create my-web-app-prod \
--repo https://github.com/<user>/helm-demo.git \
--path my-web-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace production \
--sync-option CreateNamespace=true \
--values values-prod.yaml
- Repeat
--valuesfor several files, later ones win - Precedence (low to high): chart
values.yaml,--valuesfiles, inlinevaluesObject/values,--helm-setparameters
Declarative:
spec:
source:
repoURL: https://github.com/<user>/helm-demo.git
path: my-web-app
helm:
releaseName: web
valueFiles:
- values-prod.yaml
parameters:
- name: image.tag
value: "1.26"
valuesObject:
replicaCount: 5
Chart from a Helm repo
argocd repo add https://stefanprodan.github.io/podinfo --type helm --name podinfo
argocd app create podinfo \
--repo https://stefanprodan.github.io/podinfo \
--helm-chart podinfo \
--revision 6.* \
--dest-server https://kubernetes.default.svc \
--dest-namespace podinfo \
--sync-option CreateNamespace=true \
--helm-set replicaCount=2
argocd app sync podinfo
helm search repo podinfo --versions | head
--revisionis the chart version, it accepts a constraint (6.*); pin an exact version in prod- Public repos don’t need
repo add, only for credentials - OCI charts:
--repo <registry-host>/<path>with--helm-chart <name>, add the registry withargocd repo add <host> --type helm --enable-oci
Helm hooks
- Argo CD maps Helm hooks to its own:
pre-install/pre-upgrade->PreSync,post-install/post-upgrade->PostSync,pre-delete/post-delete->PreDelete/PostDelete(newer versions),hook-weight-> sync wave hook-delete-policymaps to the Argo CD hook delete policy- Because there is no release,
pre-installhooks run on every sync, not only the first install - If a resource has both kinds of annotation, the Argo CD one wins
- Prefer Argo CD annotations on new charts, see lab 07
Dependencies
Chart.yaml:
dependencies:
- name: podinfo
version: 6.7.1
repository: https://stefanprodan.github.io/podinfo
condition: podinfo.enabled
helm dependency update my-web-app
git add my-web-app/Chart.yaml my-web-app/Chart.lock
- Argo CD runs
helm dependency build, which needsChart.lockcommitted - Don’t commit the downloaded
charts/*.tgzunless the repo isn’t reachable from the repo-server - Dependency values live under the dependency name in
values.yaml(podinfo: {enabled: true, replicaCount: 1})
Helm + Kustomize
Two ways:
- Render once to static YAML and overlay it:
mkdir -p kustomize-helm/base kustomize-helm/overlays/dev
helm template my-web-app ./my-web-app > kustomize-helm/base/manifests.yaml
# kustomize-helm/base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- manifests.yaml
# kustomize-helm/overlays/dev/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: dev
resources:
- ../../base
patches:
- target:
kind: Deployment
name: my-web-app
patch: |-
- op: replace
path: /spec/replicas
value: 1
argocd app create my-web-app-kustomize-dev \
--repo https://github.com/<user>/helm-demo.git \
--path kustomize-helm/overlays/dev \
--dest-server https://kubernetes.default.svc \
--dest-namespace dev \
--sync-option CreateNamespace=true
- Downside: the static render goes stale when the chart changes
- Or have kustomize inflate the chart (
helmCharts:inkustomization.yaml) and enablekustomize.buildOptions: --enable-helminargocd-cm
Cleanup
argocd app delete my-web-app-helm my-web-app-prod podinfo my-web-app-kustomize-dev --yes
kubectl delete namespace production podinfo dev --ignore-not-found
argocd repo rm https://stefanprodan.github.io/podinfo
argocd repo rm https://github.com/<user>/helm-demo.git
- Last one only if the repo was added; remove the local
helm-demodir