How to upgrade the helm chart deployment using a file - kubernetes

Below is Helm code to install
helm install coreos/kube-prometheus --name kube-prometheum --namespace monitoring -f kube-prometheus.yml
by this way we can override the value.yml values with the values present in kube-prometheus.yml.
Is there any way by which we can first install and then update the value.yml from kube-prometheus.yml file.
I can use helm upgrade releasename kube-prometheumafter changing the value.yml file directly. I don't want that
Use case:
Initially, I used an image with tag 1.0 in value.yml. Now I have below code in kube-prometheus.yml just to update the image tag
prometheusconfigReloader:
image:
tag: 2.0
Instead of deleting and creating again. I want to upgrade it. This is just for example, there could be multiple values. that is why I can't use -set.

So you first run helm install coreos/kube-prometheus --name kube-prometheum --namespace monitoring -f kube-prometheus.yml with your values file set to point at 1.0 of the image:
prometheusconfigReloader:
image:
tag: 1.0
Then you change the values file or create a new values file or even create a new values file containing:
prometheusconfigReloader:
image:
tag: 2.0
Let's say this file is called kube-prometheus-v2.yml Then you can run:
helm upgrade -f kube-prometheus-v2.yml kube-prometheum coreos/kube-prometheus
Or even:
helm upgrade -f kube-prometheus.yml -f kube-prometheus-v2.yml kube-prometheum coreos/kube-prometheus
This is because both values file overrides will be overlaid and according to the helm upgrade documentation "priority will be given to the last (right-most) value specified".
Or if you've already installed and want to find out what the values file that was used contained then you can use helm get values kube-prometheum

Related

Helm template - Overriding values file

I am currently trying to test some changes, specifically to see if a chart picks up/inherits changes from a top level values file. This top level values file should override any settings in the values file for this chart. To test this, I am trying to use the following command:
helm template --values path/to/top/level/values.yaml path/to/chart > output.yaml
However, when viewing the output for this, the chart still retains the values defined in the chart, and not the values that have been set in the top level values file.
I have tried a number of variations of this command, such as:
helm template path/to/chart --values path/to/top/level/values.yaml > output.yaml
helm template -f path/to/chart/values.yaml --values path/to/top/level/values.yaml > output.yaml
helm template path/to/top/level/values.yaml --values path/to/chart > output.yaml
Am I using this command correctly? Is what I am trying to achieve only possible when doing a helm install or upgrade? e.g. https://all.docs.genesys.com/PrivateEdition/Current/PEGuide/HelmOverrides
Overriding values from a parent (you call it top-level) chart mychart works like a charm and exactly as described in the Helm docs.
A values.yaml in folder mychart/charts/mysubchart
dessert: cake
can be overriden by a values.yaml in folder mychart
mysubchart:
dessert: ice cream
Any directives inside of the mysubchart section will be sent to the mysubchart chart.
Rendering the parent (top-level) chart works like that:
helm template mychart -f mychart/values.yaml
What if what you want is to combine from 2 yaml files, is it possible?
Example:
values.yaml:
blackBoxSidecar:
enabled: true
targets:
- target: esb:443
module: tcp_connect
values-namespace.yaml:
blackBoxSidecar:
targets:
- target: rabbitmq-namespace:443
module: tcp_connect
What I want to get is:
blackBoxSidecar:
enabled: true
targets:
- target: esb:443
module: tcp_connect
- target: rabbitmq-namespace:443
module: tcp_connect

Helmchart values yaml override with helmfile

I try to my custom chart's values.yaml change with overridevalue.yaml to override values. However when I install the chart with helm repo add command and try to reach values yaml it throws me "values.yaml does not exist in ".".
Helm automatically uses values.yaml file from chart's root directory.
you can pass additional values or override existing ones by passing the file during installation:
$ helm install -f override_values.yaml app ./app
you can pass multiple -f <values_yaml> .. ... The priority will be given to the last (right-most) file specified for overriding existing values.

How to render only selected template in Helm?

I have ~20 yamls in my helm chart + tons of dependencies and I want to check the rendered output of the specific one. helm template renders all yamls and produces a hundred lines of code. Is there a way (it would be nice to have even a regex) to render only selected template (by a file or eg. a name).
From helm template documentation
-s, --show-only stringArray only show manifests rendered from the given templates
For rendering only one resource use helm template -s templates/deployment.yaml .
If you have multiple charts in one directory:
|helm-charts
|-chart1
|--templates
|---deployment.yaml
|--values.yaml
|--Chart.yaml
|...
|- chart2
If you want to generate only one file e.g. chart1/deployment.yaml using values from file chart1/values.yaml follow these steps:
Enter to the chart folder:
cd chart1
Run this command:
helm template . --values values.yaml -s templates/deployment.yaml --name-template myReleaseName > chart1-deployment.yaml
Generated manifest will be inside file chart1-deployment.yaml.

How to show available updates for installed charts

Is there a way to use Helm to show available chart updates for installed charts?
For example I have a "web-app" chart installed as "test" with version 1.2.4, but in my repo 1.2.7 is available:
# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test default 1 2020-06-04 07:33:07.822952298 +0000 UTC deployed web-app-1.2.4 0.0.1
# helm search repo myrepo
NAME CHART VERSION APP VERSION DESCRIPTION
myrepo/ingress 0.1.0 1.16.0 A Helm chart for Kubernetes
myrepo/sandbox 1.2.3 1.16.0 A Helm chart for Kubernetes
myrepo/web-app 1.2.7 0.0.1 A Helm chart for Kubernetes
My goal is to write a script to send notifications of any charts that need updating so that I can review and run updates. I'd be happy to hear about any devOps style tools that do this,
As of August 28th 2022, there is no way of knowing from which repository an already installed helm chart came from.
If you want to be able to do some sort of automation, currently you need to track the information of which chart came from which repo externally.
Examples would be: storing configuration in Source Control, Installing charts as argo apps (if you're using argocd), a combination of both, etc.
Now since this question doesn't describe the use of any of these methods, I'll just make an assumption and give an example based on of the methods I mentioned.
Let's say you store all of the helm charts as dependencies of some local chart in your source control.
An example would be a Chart.yaml that looks something like this:
apiVersion: v2
name: chart-of-charts
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
dependencies:
- name: some-chart
version: 0.5.1
repository: "https://somechart.io"
- name: web-app
version: 0.2.2
repository: "https://myrepo.io"
What you could do in this case is traverse through the dependencies and perform a lookup to compare the versions in the .yaml vs versions available.
An example of a bash script:
#!/bin/bash
# requires:
# - helm
# - yq (https://github.com/mikefarah/yq)
chart = Chart.yaml
length=$(yq '.dependencies | length' $chart)
for i in $(seq $length $END); do
iter=$(($i-1))
repo=$(yq .dependencies[$iter].repository $chart)
name=$(yq .dependencies[$iter].name $chart)
version=$(yq .dependencies[$iter].version $chart)
# only if this app points to an external helm chart
if helm repo add "repo$iter" $repo > /dev/null 2>&1
then
available_version=$(helm search repo "repo$iter/$name" --versions | sed -n '2p' | awk '{print $2}')
if [ "$available_version" != "$version" ]; then
echo APP: $(echo $chart | sed 's|/Chart.yaml||')
echo repository: $repo
echo chart name: $name
echo current version: $version Available version: $available_version
echo
fi
fi
done
With the command
helm search repo --regexp "myrepo/web-app" --versions
you might get all available versions.

How to pass a file using values file in helm chart?

I want to pass a certificate to the helm chart and currently I am passing using --set-file global.dbValues.dbcacertificate=./server.crt but instead i want to pass the file in values file of helm chart.
The Values.yaml file reads
global:
dbValues:
dbcacertificate: <Some Way to pass the .crt file>
According to the relevant documentation, one must pre-process a file that is external to the chart into a means that can be provided via --set or --values, since .Files.Get cannot read file paths that are external to the chart bundle.
So, given the following example template templates/secret.yaml containing:
apiVersion: v1
kind: Secret
data:
dbcacertificate: {{ .Values.dbcacertificate | b64enc }}
one can use shell interpolation as:
helm template --set dbcacertificate="$(cat ./server.crt)" .
or, if shell interpolation is not suitable for your circumstances, you can pre-process the certificate into a yaml compatible format and feed it in via --values:
$ { echo "dbcacertificate: |"; sed -e 's/^/ /' server.crt; } > ca-cert.yaml
$ helm template --values ./ca-cert.yaml .