<p>I want to use the <code>pre-install</code> hook of helm,</p>

<p><a href="https://github.com/helm/helm/blob/master/docs/charts_hooks.md" rel="nofollow noreferrer">https://github.com/helm/helm/blob/master/docs/charts_hooks.md</a></p>

<p>in the docs its written that you need to use annotation which is clear but 
what is not clear how to combine it ? </p>

<pre><code>apiVersion: ...
kind: ....
metadata:
  annotations:
    "helm.sh/hook": "pre-install"

</code></pre>

<p>for my case I need to execute a bash script which create some env variable , where should I put this pre-hook script inside my chart that helm can use </p>

<p>before installation ? </p>

<p>I guess I need to create inside the <code>templates</code> folder a file which called: <code>pre-install.yaml</code> is it true? if yes where should I put the commands which create the env variables during the installation of the chart?</p>

<p><strong>UPDATE</strong>
The command which I need to execute in the <code>pre-install</code> is like:</p>

<pre><code>export DB=prod_sales 
export DOMAIN=www.test.com
export THENANT=VBAS 
</code></pre>

<p>A Helm hook launches some other Kubernetes object, most often a Job, which will launch a separate Pod.  Environment variable settings will only effect the current process and children it launches later, in the same Docker container, in the same Pod.  That is: you can't use mechanisms like Helm pre-install hooks or Kubernetes initContainers to set environment variables like this.</p>

<p>If you just want to set environment variables to fixed strings like you show in the question, you can <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/" rel="nofollow noreferrer">directly set that in a Pod spec</a>.  If the variables are, well, variable, but you don't want to hard-code them in your Pod spec, you can also <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">put them in a ConfigMap and then set environment variables from that ConfigMap</a>.  You can also use Helm templating to inject settings from install-time configuration.</p>

<pre><code>env:
  - name: A_FIXED_VARIABLE
    value: A fixed value
  - name: SET_FROM_A_CONFIG_MAP
    valueFrom:
      configMapKeyRef:
        name: the-config-map-name
        key: someKey
  - name: SET_FROM_HELM
    value: {{ .Values.environmentValue | quote }}
</code></pre>

<p>With the specific values you're showing, the Helm values path is probably easiest.  You can run a command like</p>

<pre><code>helm install --set db=prod_sales --set domain=www.test.com ...
</code></pre>

<p>and then have access to <code>.Values.db</code>, <code>.Values.domain</code>, <em>etc.</em> in your templates.</p>

<p>If the value is really truly dynamic and you can't set it any other way, you can use a Docker entrypoint script to set it at container startup time.  In <a href="https://stackoverflow.com/questions/55921914/how-to-source-a-script-with-environment-variables-in-a-docker-build-process/55922307#55922307">this answer</a> I describe the generic-Docker equivalents to this, including the entrypoint script setup.</p>
