Shared dependencies with HELM - kubernetes

So, is it possible to share the same pod among helm packages with a common reference. Example:
Scenario:
Package A
...
- requirements.yml
require: C
Package B
...
- requirements.yml
require: C
When I run:
helm install A
helm install B
These two pods for A and B project use the same C pod.
Is it possible? Theres a documentation to help me with that?
PS: The C package in my case is a broker, but both A & B package can be deployed separately.

This should work fine with Helm. A little bit of background here. One key aspect here is update:
created/updated in that order.
When you update an object, i.e, kubectl apply on a Pod/Deployment/Service/etc if the object exists it won't be changed, so you'll end up with the same object in the end.
Also, Kubernetes objects with the same name use the idempotency principle:
All objects will have a unique name to allow idempotent creation and retrieval
In your example:
helm install stable/packageA => which also installs PackageC
helm install stable/packageB => will update PackageC, but it's already present and won't change.
You have to make sure that the dependencies for PackageA for PackageB are exactly the same version of PackageC.

Related

multiple inclusion of helm dependency

Helm Chart A is a library chart and defines a template function f1
Chart B adds A as a dependency
Chart C adds both A and B as dependencies.
Requirement here is that App B can be deployed by itself, but App C needs B to be deployed as well.
Now A.tgz is present in C/charts as well as in B/charts directory.
In such case I have noticed that template function f1 from C/charts/A.tgz gets executed.
Are there any best practices for this situation?

Helm - Error: INSTALLATION FAILED: rendered manifests contain a resource that already exists

I have an application "A" which requires postgres database. Once I deploy the helm chart it deploys the child dependent chart postgres.
helm install application_A -n mynamspace ./applicationA-0.1.0.tgz
Now I have another application "B" which also requires postgres database. I wish to deploy the application B in the same namespace but it should not deploy new postgres POD as it is already available from Application A's deployment.
helm install application_B -n mynamspace ./applicationB-0.1.0.tgz
It fails with the following error -
Error: INSTALLATION FAILED: rendered manifests contain a resource that already exists
I want helm to recognize that the dependency of application 'B' is already deployed with the desired version and hence it should automatically avoid deploying the dependent chart.
I am aware of conditional deployment of subchart. It requires me to find out what is already available using shell script to toggle the condition while deploying Application B.
Is there any way in helm to automatically avoid deploying subchart if it is already deployed?
helm version - v3.8.0
Ideally there should not be any relation between two helm release installations. Each helm installation would always try to install their components. Here, it could be failing because of the hardcoded name of resource. Just for your use case, you can use helm in-built lookup function to see if resource exist do not create.
link:
https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-function

Events which can be used during helm upgrade to be consumed in the docker image

I am very new to Helm and Kubernetes. I have a use case where, whenever there is a helm upgrade
helm upgrade xxx --values yy.yaml
I need to trigger invocation of a method in my docker image which is deployed onto the kubernetes pods ,so that i can work on the changes encountered in yy.yaml in the image code . Do we have some way of doing it ? Please help me here.
Though your problem is not clear to me but i think, You can use helm hook to do the same thing. Please check documentation.
You can certainly use pre-upgrade hook to invoke your function.

How do i find the 'from' Chart version at a helm upgrade?

I am using helm built in object 'Release.isUpgrade' to ensure an init-container is only run at upgrade.
I want to only run the init-container when upgrading from a specific Chart version.
Is it possible to get the 'from' Chart version in a helm upgrade ?
It doesn't look like this information is published either in the .Release object or through information available to a hook job.
You probably want a pre-upgrade hook and not an init container. If you have multiple replicas on your deployments, the init container will run on all of them; even if you have just one, if the node it's on fails and is replaced, the replacement will re-run the init container. A pre-upgrade hook will run just once, regardless of how the corresponding deployments are configured.
That hook will be a separate pod (and will require writing code), so within that you can do whatever you want. You can give it read access to the Kubernetes API to get the definition of an existing deployment, for example, and then look at its labels or container image tag to find out what version of the chart/application is running now. (There are standard labels that can help with this.) You could also make the upgrade step just look for its own outputs: if object X is supposed to exist, create it if it's not there, without focusing on specific versions.

Verify that all values for a kubernetes helm chart have been used

I'd like to check that my kubernetes helm chart does not define unused values in values.yaml. This should include any subcharts such that if you've defined subchart.foo.bar: ??? in the top-level values.yaml that key is definitely used in the subchart, or possibly as a short-cut mentioned in the subchart/values.yaml.
This is needed to prevent us from shipping bogus "documentation" in the values.yaml, for example if a key in a subchart has been changed or removed.
Ideally there would also be some possibility to report on which subchart values have not been overridden in the top-level chart, though this is less concerning.
Are there any existing tools that can help with this?
Since the Helm v3 release you can now define a schema for your values. On commands like helm install your provided values are automatically validated against the schema.
Please see the official documentation: https://helm.sh/docs/topics/charts/#schema-files
Schema validation works for subcharts too, this is also mentioned in the documentation on the link above.
AFAIK, there isn't a tool for that. However, it shouldn't be that hard to make one, even using bash. For example, you need to export all key/value pairs like this test.test1.test2 and grep for that string recursively in the templates folder. If you want to read yaml using bash, you can install shyaml. If you know how to code in Python, even better.
helm lint --detect-unused-values