Helm3 : Overriding image tag value - kubernetes

I was trying to override the image tag in Helm3 using upgrade command by setting the variable at command line but it did not work. Has someone tried this feature in Helm3.
Stuck for last couple of days, would be helpful to know your views.
Deployment manifest file looks like this:-
containers:
- image: {{ .Values.image.repository }}:{{.Values.image.tag}}
imagePullPolicy: Always
Executing this command from command line:-
> helm upgrade resources-dev resources --set image.tag=72615 --dry-run --debug
does not override image tag value from 72626 to 72615
containers:
- image: aksresourcesapi.azurecr.io/microservicesinitiative:72626
imagePullPolicy: Always
Deployment file
Command Results:-
helm upgrade resources-dev resources --set image.tag=72615 --reuse-values
Command Results of
helm upgrade resources-dev resources --set-string image.tag=72615

You should specify to helm that it is a string value. It is done with --set-string flag.
Also use --reuse-values in order to reuse the last release’s values and merge in any overrides from the command line via — set and -f
Executing the following command will solve the problem:
helm upgrade resources-dev resources --reuse-values --set-string image.tag=72615 --dry-run --debug

Issue is identified, it's not with a --set flag but with the kind of directory structure I have for charts.
while executing the command
helm upgrade resources-dev resources --set image.tag=72615
one level up where resources (charts) folder is, it looks for image.tag in "Values.yaml" file of resources folder and not the "Values.yaml" file of backend folder and thus the tags are not replaced.
By executing the below command with backend.imge.tag worked
helm upgrade resources-dev resources --install --set backend.image.tag=72615

Related

How can I pass the correct parameters to Helm, using Ansible to install GitLab?

I'm writing an Ansible task to deploy GitLab in my k3s environment.
According to the doc, I need to execute this to install GitLab using Helm:
$ helm install gitlab gitlab/gitlab \
--set global.hosts.domain=DOMAIN \
--set certmanager-issuer.email=me#example.com
But the community.kubernetes.helm doesn't handle --set parameters and only call helm with the --values parameter.
So my Ansible task looks like this:
- name: Deploy GitLab
community.kubernetes.helm:
update_repo_cache: yes
release_name: gitlab
chart_ref: gitlab/gitlab
release_namespace: git
release_values:
global.hosts.domain: example.com
certmanager-issuer.email: info#example.com
But the helm chart still return the error You must provide an email to associate with your TLS certificates. Please set certmanager-issuer.email.
I've tried manually in a terminal, and it seems that the GitLab helm chart requires --set parameters and fail with --values. But community.kubernetes.helm doesn't.
What can I do?
Is there a bug on GitLab helm chart side?
it seems that the GitLab helm chart requires --set parameters and fail with --values
That is an erroneous assumption; what you are running into is that --set splits on . because otherwise providing fully-formed YAML on the command line would be painful
The correct values are using sub-objects where the . occurs:
- name: Deploy GitLab
community.kubernetes.helm:
update_repo_cache: yes
release_name: gitlab
chart_ref: gitlab/gitlab
release_namespace: git
release_values:
global:
hosts:
# https://gitlab.com/gitlab-org/charts/gitlab/-/blob/v4.4.5/values.yaml#L47
domain: example.com
# https://gitlab.com/gitlab-org/charts/gitlab/-/blob/v4.4.5/values.yaml#L592-595
certmanager-issuer:
email: info#example.com

Set extraEnvs ingress variable

I'm trying to use extraEnv property in order to add additional environment variables to set in the pod using helm charts.
I have a values.yaml file that includes:
controller:
service:
loadBalancerIP:
extraEnvs:
- name: ev1
value:
- name: ev2
value
first I've set the loadBalancerIP the following way:
helm template path/charts/ingress --set nginx-ingress.controller.service.loadBalancerIP=1.1.1.1 --output-dir .
In order to set extraEnvs values I've tried to use the same logic by doing:
helm template path/charts/ingress --set nginx-ingress.controller.service.loadBalancerIP=1.1.1.1 --set nginx-ingress.controller.extraEnvs[0].value=valueEnv1--set nginx.controller.extraEnvs[1].value=valueEnv2--output-dir .
But it doesn't work. I looked for the right way to set those variables but couldn't find anything.
Helm --set has some limitations.
Your best option is to avoid using the --set, and use the --values flag with your values.yaml file instead:
helm template path/charts/ingress \
--values=values.yaml
If you want to use --set anyway, the equivalent command should have this notation:
helm template path/charts/ingress \
--set=controller.service.loadBalancerIP=1.1.1.1 \
--set=controller.extraEnvs[0].name=ev1,controller.extraEnvs[0].value=valueEnv1 \
--set=controller.extraEnvs[1].name=ev2,controller.extraEnvs[1].value=valueEnv2 \
--output-dir .

Namespace deployment issue in Kubernetes Helm Chart

I am now testing the deployment into different namespace using Kubernetes. Here I am using Kubernetes Helm Chart for that. In my chart, I have deployment.yaml and service.yaml.
When I am defining the "namespace" parameter with Helm command helm install --upgrade, it is not working. When I a read about that I found the statement that - "Helm 2 is not overwritten by the --namespace parameter".
I tried the following command:
helm upgrade --install kubedeploy --namespace=test pipeline/spacestudychart
NB Here my service is deploying with default namespace.
Screenshot of describe pod:
Here my "helm version" command output is like follows:
docker#mildevdcr01:~$ helm version
Client: &version.Version{SemVer:"v2.14.3",
GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.3",
GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Because of this reason, I tried to addthis command in deployment.yaml, under metadata.namespace like following,
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "spacestudychart.fullname" . }}
namespace: test
I created test and prod, 2 namespaces. But here also it's not working. When I adding like this, I am not getting my service up. I am not able to accessible. And in Jenkins console there is no error. When I defined in helm install --upgrade command it was deploying with default namespace. But here not deploying also.
After this, I removed the namespace from deployment.yaml and added metadata.namespace like the same. There also I am not able to access deployed service. But Jenkins console output still showing success.
Why namespace is not working with my Helm deployment? What changes I need to do here for deploying test/prod instead of this default namespace.
Remove namespace: test from all of your chart files and helm install --namespace=namespace2 ... should work.
On Helm 3.2+, I would suggest (based on this thread) to move the namespace creation to the CLI:
1 ) Add the --create-namespace after the -n flag:
helm upgrade --install <name> <repo> -n <namespace> --create-namespace
2 ) Inside the different resources - pass the Release namespace:
namespace: {{ .Release.Namespace }}

how install grafana with helm and with a path "/grafana" instead of path "/"

I've define a Ingress rule on path /grafana
I understand that I need also to configure root_url
I'm looking for the correct way to pass the root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/ with a command line like :
helm install --namespace grafana -n grafana stable/grafana --set rbac.pspEnabled=false --set grafana.ini="{root_path = https://ingress-ops.nd-int-ops-paas.itn/grafana/ }"
I don't know what's wrong
--set 'grafana\.ini'.server.root_url=https://ingress-ops.nd-int-ops-paas.itn/grafana
works fine

Helm: How to Override Value with Periods in Name

I am trying to script setup of Jenkins so that I can create and tear down Jenkins clusters programmatically with helm. I've hit an annoying snag where I cannot set a key with dots in the name. My helm values.yaml file looks like this:
---
rbac:
install: true
Master:
HostName: jenkins.mycompany.com
ServiceType: ClusterIP
ImageTag: lts
InstallPlugins:
- kubernetes
- workflow-aggregator
- workflow-job
- credentials-binding
- git
- blueocean
- github
- github-oauth
ScriptApproval:
- "method groovy.json.JsonSlurperClassic parseText java.lang.String"
- "new groovy.json.JsonSlurperClassic"
- "staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods leftShift java.util.Map java.util.Map"
- "staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods split java.lang.String"
- "method java.util.Collection toArray"
- "staticMethod org.kohsuke.groovy.sandbox.impl.Checker checkedCall java.lang.Object boolean boolean java.lang.String java.lang.Object[]"
- "staticMethod org.kohsuke.groovy.sandbox.impl.Checker checkedGetProperty java.lang.Object boolean boolean java.lang.Object"
Ingress:
Annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
TLS:
- secretName: jenkins-mycompany-com
hosts:
- jenkins.mycompany.com
Memory: "2Gi"
# This breaks the init container
# RunAsUser: 1000
# FSGroup: 1000
Agent:
Enabled: false
ImageTag: latest
After installing cert-manager, external-dns, nginx-ingress (for now via a bash script) I install it like so:
helm install --values helm/jenkins.yml stable/jenkins
I failed to read the letsencrypt docs at all, so throughout the course of testing I used my production quota. I want to be able to add an annotation to the Ingress: certmanager.k8s.io/cluster-issuer: letsencrypt-staging so that I can continue testing (and set this as the default in the future, overriding when I'm ready for production).
The trouble is... I can't figure out how to pass this via the --set flag, since there are periods in the key name. I've tried:
helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations.certmanager.k8s.io/cluster-issuer=letsencrypt-staging
and
helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations.certmanager\.k8s\.io/cluster-issuer=letsencrypt-staging
I can of course solve this by adding a value that I use as a flag, but it's less explicit. Is there any way to set it directly?
You need to enclose the key with quotations and then escape the dots
helm install --values helm/jenkins.yml stable/jenkins --set Master.Ingress.Annotations."certmanager\.k8s\.io/cluster-issuer"=letsencrypt-staging
Use \ to escape the dots in the key. Quotation marks are required to prevent shell interpreting the \ character.
helm install --values helm/jenkins.yml stable/jenkins --set 'Master.Ingress.Annotations.certmanager\.k8s\.io/cluster-issuer=letsencrypt-staging'
Helm requires these characters to be escaped: . [ , =
Source: https://paul-boone.medium.com/helm-chart-install-advanced-usage-of-the-set-argument-3e214b69c87a
If you are doing this in Jenkins within a shell script like this:
sh """
...
--set-string datasources.'datasources\\.yaml'.datasources[1].secureJsonData.token=$TOKEN \
...
"""
I'm not sure if this is the best explanation but I'll give it a shot....
Groovy interprets shell scripts with backslashes differently than a normal shell script because in Jenkins this is being written inside a shell script. The double escape is needed so Groovy ignores the first backslash and then helm ignores the second. This problem took me too long to solve so I'd figure I'd share what I found for anyone stuck in the same boat.