Using Helm with Kustomize effectively.
Kustomize and Helm are both effective tools for managing things within Kubernetes. I am a big fan of Kustomize, and use it to manage my Kubernetes cluster, hydra.
Although I primarily use Kustomize, I maintain a number of services that have a recommended deployment option of Helm, so what I would do is template out files to disk and then use Kustomize to merge and deploy them. This gives the benefit of being able to kustomize build
everything within my cluster, instead of doing helm install
for a number of deployments.
Since I try to stick to kustomize, I would often template out Helm deployments to a file, then deploy with kustomize. This was the going method for some of my deployments, until the helmChartInflationGenerator
was added to kustomize.
The helmChartInflationGenerator
allows me to use a Helm chart as a source, and directly use it from Kustomize. It has a number of options, but it's pretty simple to use. Lets go through an example with deploying haproxy-ingress.
Example: Deploying Haproxy Ingress
Lets start by creating a kustomization.yaml
# kustomization.yaml
# Tell kustomize to use the generator in chartInflator.yaml
generators:
- chartInflator.yaml
Next, we'll write the chartInflator.yaml
.
# chartInflator.yaml
apiVersion: builtin
kind: HelmChartInflationGenerator
metadata:
# The name here doesn't matter.
name: notImportantHere
# The name of the chart to use
chartName: haproxy-ingress
# The name of the release
releaseName: hydra
# Path to a values.yaml
values: values.yaml
# Namespace to deploy to
releaseNamespace: ingress-controller
# URL to the Repo
chartRepoUrl: https://haproxy-ingress.github.io/charts
The last step is to create a values.yaml
(or if you're happy with the defaults, you can just remove the line from chartInflator.
)
The default behavior of the chart inflation generator is to overwrite the defaults, and keep any that aren't specified, so you can create some pretty minimal values.yaml
files. (the one I use is below)
# values.yaml
controller:
## Annotations to be added to controller pods
##
podAnnotations:
config.linkerd.io/skip-inbound-ports: 80, 443
extraArgs:
watch-ingress-without-class:
# ConfigMap to configure haproxy ingress
config:
proxy-protocol: "no"
use-proxy-protocol: "True"
config-frontend: |
capture request header Host len 32
capture request header X-REAL-IP len 64
capture request header User-Agent len 200
service:
loadBalancerIP: "10.0.7.20"
stats:
enabled: true
metrics:
enabled: true
logs:
enabled: true
defaultBackend:
enabled: true
And that's it! It's really simple to do, but it allows you to use Helm charts that are now managed within Kustomize.
I'm currently writing some documentation for the full list of options for HelmChartInflationGenerator, which will be submitted as a PR to the Kustomize project, but it's along the same lines as above. I just wrote this because I had to look through the source code for Kustomize to find the values
option.