Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

langyizhao
langyizhao

Posted on

     

Helm Charts, with or without Kustomize

I've recently readan interesting blog about using Helm together with Kustomize.

Though it provides good information such as the difference between Templates (via Helm) vs Overlays (via Kustomize), I would argue that, in a real deployment, the same effect can be achieved with Helm alone without the extra complexity of Kustomize.

To avoid repeating the details in the original blog, I just provide the files to simulate the approach used by the original blog here:https://github.com/langyizhao/helm-charts-with-or-without-kustomize/tree/master/with-kustomize

The distilled bare minimum steps are:

  1. kustomize build
  2. helm template
  3. kubectl apply -k

3 steps are actually not too bad. The major clutter is the introduction of the temporary folder and temporary template files and the easily-confusing order of applying overlays.

So how do we achieve the effect of overlays by just using templates? We will need some logic when drafting the template. Fortunately the Go template language under the hood of Helm charts easily support such trivial logic and some non-trivial ones.

One possible implementation is:

# from without-kustomize/templates/pod.yaml{{- if and .Values.employeeName .Values.employeeDepartment }}    args: ["/bin/echo My name is {{ .Values.employeeName }}. I work for {{ .Values.employeeDepartment }} department. Our company name is {{ .Values.companyName}}"]{{ else }}    args: ["/bin/echo Hello! My company name is {{ .Values.companyName }}"]{{ end }}
Enter fullscreen modeExit fullscreen mode

In this case we will only render the complex form when the necessary values exists in the values.yaml file provided by our customer and safely default to the simple form when they are missing.

No pre or post rendering needed and Helm alone handles everything.

Feel free to check the simple examples out and try it yourself:

This is the example code forhttps://dev.to/langyizhao/helm-charts-with-or-without-kustomize-2f1j

  1. Example 1:helm template without-kustomize -f values1.yaml

Expected last line:args: ["/bin/echo Hello! My company name is ABC Company"]

  1. Example 2:helm template without-kustomize -f values2.yaml

Expected last line:args: ["/bin/echo My name is Gary. I work for Marketing department. Our company name is ABC Company"]

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
hacktron95 profile image
Osama Nabil
  • Joined

Hey, thanks sharing
I would like to argue that the approach you mentioned actually don't replace the original post's approach.

to do what you suggested for a large chart, you actually "HAVE TO" fork the chart repository and do your go-template modifications there, u will miss any updates on the original chart..etc (mentioned in the original post).

CollapseExpand
 
langyizhao profile image
langyizhao
Coding in Java, Scala, JavaScript, Python, Go, Kotlin and Haskell.Trying to focus on architecture and be more language agnostic.
  • Location
    Virginia, USA
  • Education
    University of Utah
  • Work
    Senior Software Engineer at Sonatype
  • Joined

Good point, thanks for pointing it out!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Coding in Java, Scala, JavaScript, Python, Go, Kotlin and Haskell.Trying to focus on architecture and be more language agnostic.
  • Location
    Virginia, USA
  • Education
    University of Utah
  • Work
    Senior Software Engineer at Sonatype
  • Joined

More fromlangyizhao

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp