Templating of the Helm charts - kubernetes

Is there a way to create own boilerplate helm chart and then generate from it helm charts for my micro services (which will differ only in chart names)?

Yes, you'd need to create a package of your base boilerplate chart and then reference it in the requirements.yaml for other charts which depend on it.
Ref: https://helm.sh/docs/developing_charts/#chart-dependencies

Use helm create command to create boiler template, then changes are up to yourself.
$ helm create mychart
Ref: https://helm.sh/docs/helm/#helm-create

Related

Build Helm chart with custom app version for Sub Charts

For a regular helm-chart I can use helm package --app-version="foo-bar" to be able to overwrite app-version while packing the helm chart.
Is there a way to achieve the same with sub-charts.
Consider the following helm-chart structure
uber-chart
\sub-chart-1
\sub-chart-2
\sub-chart-3
Is it possible to pass different app-versions to different sub-charts while packaging uber-chart?

Is it possible to define templates outside of a Helm chat?

I have multiple charts that all use the same templates. Is it possible to instruct helm to use some other templates directory, or have some shared templates that I can import/reference in some way? I would like to avoid the copy paste and have reusable templates, but at the same time keep the project/service per chart because in the future there will be some discrepancies.
How do you achieve DRY and re-usability in helm?
To me, that sounds like you want to use so called "Library Charts" ( link to helm docs).
To create one, you define a helm chart that does not actually create any Resources but only defines reusable templates and set the type property in the chart.yml to library:
apiVersion: v2
name: library-chart
description: A Helm chart for Kubernetes
type: library
version: 0.0.1
Then, you can include that helm chart as a dependency in your other charts and start using the templates defined there.

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>

How made umbrella chart update existing helm deployment

I have a umbrella chart and I want to know if it's possible to update an existing helm deployment through my requirements.yaml in my umbrella chart.
Not directly. If you did some kind of funky CRD with one of the existing Helm operators then maybe, but overall releases don't know about each other.

How to create a custom Helm chart that basically just sets values of another chart?

I'm new to Helm and I haven't quite fully grasped the concepts yet. What I'm currently trying to do is to create a custom chart that basically just sets specific values for another chart that's available in the default stable repository. Pretty much what I want to do is have this:
helm install \
-f my-custom-values.yaml \
stable/target-chart \
--name=my-release
changed into
helm install my-apps/my-release
With my-release using the same values in my-custom-values.yaml. It's essentially bundling the pre-existent chart into a new one with my custom values.
Is there a way to do this? I think I might be able to clone the source chart, but I don't feel like that's a practical thing to do.
What is the issue with the first variation? If you have a custom values.yaml that you can pass to helm why do you need to remove it from the command line?
But if you are ready to play around a bit... :)
One way of doing this would be creating your own chart, that will be mainly empty but consist of a requirements.yaml that refers to stable/target-chart.
requirements.yaml (just beside Chart.yaml)
dependencies:
- name: stable/target-chart
version: 1.0.0.0.0.0
alias: somealiasforvaluesyaml
In your values.yaml you then overwrite the values of that sub-chart:
somealiasforvaluesyaml:
keyfromthattargetchart: newvalue
subkeyfromthattargetchart:
enabled: true
setting: "value"
The alias you give in the requirements.yaml is the section in your values.yaml from your chart.
Before installing you need to tell helm to update these requirements:
helm repo update
helm dependency update
and then just helm install this (virtual?) chart. This chart does not contain any resources to it would not be called a package in linux package managers - but they also use transitional packages or packages that just are a collection of others (like the build-essential)
Considering you already have the values.yaml to overwrite the ones in the target-chart this is all a bit much? Since the cust-values .yaml to pass to install with -f just needs to contain the customization as it will ammend the values.yaml from the target-chart your first command in the question looks like the correct way to go.