May 18, 2022
Introduction
I have stumbled upon many projects that don’t share Kustomize manifests, or even Kubernetes manifests, but do have Helm charts.
Not everyone uses Helm, so I wanted to share a method can be semi-easily automated to generate k8s manifests from Helm charts.
What is Kustomize
I need the manifests to use them with Kustomize, which is a templating tool that allows you to “kustomize” the Kubernetes manifests, usually based on environments. As of a few Kubernetes versions ago, kustomize is also built into Kubernetes.
How does Kustomize Work
Kustomize vs Helm
Here is some reading material if you are interested in the differences between Kustomize and Helm.
Generate Manifests from Helm Charts
I will be using cluster-autoscaler for this example, you can see how the project has charts but not the manifests (external-dns has manifests, for example)
Let’s dive into it.
The first step is to add the autoscaler repository
helm repo add autoscaler https://kubernetes.github.io/autoscaler
Check the latest chart version
helm search repo autoscaler/cluster-autoscaler
NAME CHART VERSION APP VERSION DESCRIPTION
autoscaler/cluster-autoscaler 9.9.2 1.20.0 Scales Kubernetes worker nodes within autoscali...
autoscaler/cluster-autoscaler-chart 2.0.0 1.18.1 Scales Kubernetes worker nodes within autoscali...
Next, we need to download the latest version
helm fetch autoscaler/cluster-autoscaler --untar --untardir $PWD/tmp --version 9.9.2
I would suggest taking the values.yaml and modifying it to suite your needs. values.yaml
should contain the unique values for the changes in our environment compared to the default values that the helm chart gives us.
helm template $PWD/tmp/cluster-autoscaler --values values.yaml --namespace cluster-autoscaler --output-dir $PWD/tmp --debug
Note that we are hardcoding the namespace above (not required, depends on your deployment strategy), make sure to change/remove it if required.
Once we generate the manifests, we still need to make a few tweaks:
- (optional) Merge all RBAC related manifests into one. I like to do this as it simplifies the structure
- Move the following into the
base
directory fromtmp/cluster-autoscaler/templates
deployment.yaml
pdb.yaml
if there are any changesservice.yaml
if there are any changes- newly generated
rbac.yaml
- There are some values that we can't replace via
values.yaml
as they are built into Helm, so we have to remove them
TMP_LOC=$PWD/tmp/cluster-autoscaler/templates && cd $TMP_LOC && cat clusterrole.yaml clusterrolebinding.yaml role.yaml rolebinding.yaml serviceaccount.yaml > rbac.yaml && cd -
sed -i '' '/app.kubernetes.io\/instance/d' base/*.yaml
sed -i '' 's/RELEASE-NAME-cluster-autoscaler/cluster-autoscaler/g' base/*.yaml
Now all that is left is to create a kustomize manifest and test locally before adding it to version control.
I hope this has been useful, have a wonderful day.
Cover Photo by Syed Hussaini on Unsplash