Use Kustomize to post-render Helm charts in ArgoCD
source link: https://dev.to/camptocamp-ops/use-kustomize-to-post-render-helm-charts-in-argocd-2ml6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
In an ideal world you wouldn't have to perform multiple steps for the rendering, but unfortunately we don't live in an ideal world...
Kustomize
Nowadays, most applications that are meant to be deployed in Kubernetes provide a Helm chart to ease deployment. Unfortunately, sometimes the Helm chart is not flexible enough to do what you want to do, so you have to fork and contribute and hope that your contribution is quickly merged upstream so that you don't have to maintain your fork.
Instead of pointing to your fork, you could use Kustomize to apply some post-rendering to your templatized Helm release. This is possible natively since Helm 3.1 using the --post-process
flag.
Integration in ArgoCD
At Camptocamp, we use ArgoCD to manage the deployment of our objects into Kubernetes. Let's see how we can use Kustomize to do post-rendering of Helm charts in ArgoCD:
At first, declare a new config management plugin into your argocd-cm
configMap (the way to do it depends on the way you deployed ArgoCD):
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
configManagementPlugins: |
- name: kustomized-helm
init:
command: ["/bin/sh", "-c"]
args: ["helm dependency build || true"]
generate:
command: ["/bin/sh", "-c"]
args: ["helm template . --name-template $ARGOCD_APP_NAME --namespace $ARGOCD_APP_NAMESPACE --include-crds > all.yaml && kustomize build"]
Then add a kustomization.yaml
file next to your application's Chart.yaml
file:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- all.yaml
patchesJson6902:
- target:
group: apps
version: v1
kind: Deployment
name: myapplication
patch: |-
- op: remove
path: /spec/template/spec/securityContext
Now configure your Applications
object to use this plugin:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapplication
namespace: argocd
spec:
project: myproject
source:
path: myapplication
repoURL: {{ .Values.spec.source.repoURL }}
targetRevision: {{ .Values.spec.source.targetRevision }}
plugin:
name: kustomized-helm
destination:
namespace: myproject
server: {{ .Values.spec.destination.server }}
And... voilà!
Integration in App of Apps
One thing that I often do is to use spec.source.helm
in my Application
object to pass some values that comes from my app of apps. This is not possible using a configuration plugin as the keys helm
and plugin
are mutually exclusive.
The workaround I found is to use plugin's envs. You have to change your config management plugin configuration to (note the $HELM_ARGS
):
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
configManagementPlugins: |
- name: kustomized-helm
init:
command: ["/bin/sh", "-c"]
args: ["helm dependency build || true"]
generate:
command: ["/bin/sh", "-c"]
args: ["echo \"$HELM_VALUES\" | helm template . --name-template $ARGOCD_APP_NAME --namespace $ARGOCD_APP_NAMESPACE $HELM_ARGS -f - --include-crds > all.yaml && kustomize build"]
You'll then be able to use this in your Application
:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapplication
namespace: argocd
spec:
project: myproject
source:
path: myapplication
repoURL: {{ .Values.spec.source.repoURL }}
targetRevision: {{ .Values.spec.source.targetRevision }}
plugin:
name: kustomized-helm
env:
- name: HELM_ARGS
value: "--set targetRevision={{ .Values.spec.source.targetRevision }}"
destination:
namespace: myproject
server: {{ .Values.spec.destination.server }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapplication
namespace: argocd
spec:
project: myproject
source:
path: myapplication
repoURL: {{ .Values.spec.source.repoURL }}
targetRevision: {{ .Values.spec.source.targetRevision }}
plugin:
name: kustomized-helm
env:
- name: HELM_VALUES
value: |
targetRevision: {{ .Values.spec.source.targetRevision }}
destination:
namespace: myproject
server: {{ .Values.spec.destination.server }}
Recommend
-
28
前言 本人是helm的重度用户,但是吧越用越不爽。 。 。 helm v2版本三大弊病: ...
-
10
Today, we’ll talk about some deployment tools in the Kubernetes world. We’ll talk a little bit about why tools are used on top of kubectl. We’ll compare 3 different tools in the Kubernetes world focused on the deployment side of things:
-
11
Posted 12 days ago2020-12-08T00:00:00+01:00 by Wolfgang Ofner In my last post, I explained how Helm works and how to add it to your microservice. This post is going to be more practical. Helm is a package manage...
-
2
Helm & Kustomize better together ❤️Skip to content PUBLISHED May 6th, 2020 BY Povilas 8mins read In this...
-
7
2021 年 Kubernetes 的开发者工具:Helm、Kustomize 和 Skaffold ...
-
2
如果你经常使用 Kubernetes,那么应该对 Helm 和 Kustomize 不陌生,这两个工具都是用来管理 Kubernetes 的资源清单的,但是二者有着不同的工作方式。 Helm 使用的是模板,一个 Helm Chart 包中包含了很多模板和值文件,当被渲染时模板中的变量会使用值...
-
4
Implement GitOps on Kubernetes with ArgoCD and Kustomize Nov 20, 2020 GitOps is a term first coined and popularized at Weaveworks. GitOps can in it’s most concise form be described as a philospohy or a workflow on how in...
-
4
Siv Scripts Solving Problems Using Code As a learning exercise, I migrated all my side proje...
-
7
Helm: Render Chart Templates Locally – Example Helm chart templates in a combination with a values.yaml file, generate manifest files which are YAML-formatted Kubernetes resource descriptions.
-
4
ArgoCD: Use Upsert Flag to Force Update In ArgoCD, if you try to add/update some object that already exists, you my receive an error as follows: Unable to connect repository: existing reposito...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK