How to use a Helm template in multiple repositories? - kubernetes

I have several microservices that have practically the same settings in YAML, some values change (e.g. image, version, a specific environment variable ...), and they are in different repositories, with a different pipeline each. How do I use the same template between them without getting repeated code?

This is how we do it in the place I currently work.
We have our own generic Helm chart that is version controlled and hosted in our Artifactory, every parameter in that chart that may need changing is exposed in values.yaml.
The Artifactory gets added to helm as repository, then you only need separate a values.yaml for each microservice you want deployed as the chart gets sourced centrally.
helm install -f values.yaml microservice01 artifcatory/global-helm-chart
On top of that we use helmfile, but this is not necessary in order to achieve your goal.
The key points are:
make the chart generic
host it centrally
add the repository to helm.

You can also update the values.yaml from pipeline and then package the chart and deploy it..In that way you can still have the same yaml file but the values will differ from which pipeline they are deployed.
Alternatively and easy way will be to maintain different values.yaml for different environment in the helm chart itself and pass them during helm install/upgrade from pipeline.

We do it for about 90 microservices. We have common Chart and we run values file through kindof sed script which changes what we need. Then whole package gets deployed

Related

How to manage external Helm Chart dependencies

I'm very curious how I should combine my own Helm chart with a set of contributed charts, i.e. the ones of BitNami.
So say I have my own chart that defines my backend application, how do I add a dependency to the contributed MySQL chart (instead of manually crafting it myself).
Another use case would be to add ArgoCD to my own custom chart. How do I do this in a declarative manner, without running the needed commands on the cluster manually?
I'm aware of the helm repo add and helm install for 3rd party charts, but these commands do not lend them well for CI/CD because they are not idempotent. I would like my chart to be declarative, so a single helm install also installs all listed dependencies. And the weird thing is that I cannot find anything about this topic online.
Would love your feedback!

helm Chart.yaml and values.yaml

I am starting to get my arms around using Kubernetes and Helm. Most of it makes perfect sense to me. I am missing one thing though and maybe someone can answer me. Why is there a separate Chart.yaml and values.yaml file? it seems to me that it would make better sense on a helm install command to have one file with a standard name. Asking for some DevOps wisdom.
Chart.yaml contains metadata about the chart itself: its name, the chart version, a description, and similar details. In Helm 3 it can contain dependencies as well.
values.yaml contains configuration settings for the chart. This typically includes things like the image repository to pull from, where you want data to be stored, and how to make the service accessible.
When you install the chart, you can use helm install -f to supply an additional YAML file of configuration options that override things in value.yaml, or helm install --set to set a single specific value. You can't override things in the Chart.yaml.
In the template code, items in Chart.yaml and values.yaml are available in the top-level data items .Chart and .Values, respectively.

Is it possible to install a helm chart with a custom value not found in the templates or values.yaml?

I need to install a helm chart with a key/value that is not present in one of the templates and I prefer not to edit the already existing templates.
In particular, I need to change resources.limits.cpu and resources.limits.memory in k8s-job-template.yaml but resources is not even mentioned in that file.
Is there a solution for this?
The only customizations it's possible to make for a Helm chart are those the chart author has written in; you can't make arbitrary additional changes to the YAML files.
(Kustomize allows merges of arbitrary YAML content and is built into recent kubectl, but it doesn't have some of the lifecycle or advanced templating features of Helm.)
For future reference, I found a solution to this.
Simply download the chart using the following command:
helm fetch <chart> --untar --destination /local/path/to/chart
Go to the folder /local/path/to/chart/<chartname> and make the desired changes.
After this, simply install the helm chart based on the locally edited chart:
helm install /local/path/to/chart/<chartname>

Integration of Kubernetes Helm templates for a project deployment

Currently I am working with a project based on a micro service architecture. For making this project, I have 20 Spring Boot micro service projects are there. I for for every root folder I placed my Dockerfile for image building. And I am using Kubernetes cluster for deployment through Helm chart.
My confusion here that, when I created Helm chart, it giving the service.yaml and deployment.yaml inside template directory.
If I am deploying these 20 microservices, do I need to create 20 separate helm chart ? Or Can I create service for every 20 within 1 chart?
I am new to Kubernetes and Helm chart. So I am confused about the standard way of using yaml files with chart. Do I need to create 20 separate chart or can I include in 1 chart?
How can I follow the standard way of chart creation for my micro service projects please?
What I ended up doing (working with a similar stack), is create one microservice Chart, which is stored in an internal Chart repository. Inside of the Helm Chart, I gave enough configuration options, so teams have the flexibility to control their own deployments, but I made sure to set sensible defaults (e.g. make sure the Deployment utilises a RollingUpdateStrategy and readiness probes are configured with sensible defaults).
These configuration options can be passed by the values.yaml file. Teams deploy their microservice via a CICD pipeline, passing the values.yaml file to the helm command (with the -f flag).
I would certainly recommend you read the Helm Template Developer guide, before making the decision. It really depends on how similar your microservices are, but I recommend going for 1 Helm Chart if you have a homogenous environment (which also was the case for me).

Customize helm chart from stable repository

So I am using the helm chart stable/traefik to deploy a reverse proxy to my cluster. I need to customise it beyond what is possible with the variables I can set for the template.
I want to enable the dashboard service while not creating an ingress for it (I set up OpenVPN to access the traefik dashboard only via VPN).
Both dashboard-ingress.yaml and dashboard-service.yaml conditionally include the ingress or the respective service based on the same variable {{- if .Values.dashboard.enabled }}
From my experience I would fork the helm chart and push the customised version to my own repository.
Is there a way to add that customization but keep the original helm chart from the stable repository?
You don't necessarily have to push to your own repository as you could take the source code and include the chart in your own as source. For example, if you dig into the gitlab chart in their charts dependencies they've included multiple other charts as source their, not packaged .tgz files. That enables you to make changes in the chart within your own source (much as the gitlab guys have). You could get the source using helm fetch stable/traefik --untar
However, including the chart as source is still quite close to forking. If you want to upgrade to get fixes then you still have to reapply your changes. I believe your only other option is to raise the issue on the official chart repo. Perhaps for your case you could suggest to the maintainers that the ingress be included only when .Values.dashboard.enabled and a separate ingress condition is met.