<p>I'm struggling to use Helm variables within my entry script for my container, when deploying to AKS. Running locally work perfectly fine, as I'm specifying them as docker -e arguement. How do I pass arguments, either specified as helm variables and/or overwrited when issuing the helm install command?</p>
<p>Entry script start.sh</p>
<pre><code>#!/bin/bash

GH_OWNER=$GH_OWNER
GH_REPOSITORY=$GH_REPOSITORY
GH_TOKEN=$GH_TOKEN

echo &quot;variables&quot;
echo $GH_TOKEN
echo $GH_OWNER
echo $GH_REPOSITORY
echo ${GH_TOKEN}
echo ${GH_OWNER}
echo ${GH_REPOSITORY}
env
</code></pre>
<p>Docker file</p>
<pre><code># base image
FROM ubuntu:20.04

#input GitHub runner version argument
ARG RUNNER_VERSION
ENV DEBIAN_FRONTEND=noninteractive

# update the base packages + add a non-sudo user
RUN apt-get update -y &amp;&amp; apt-get upgrade -y &amp;&amp; useradd -m docker

# install the packages and dependencies along with jq so we can parse JSON (add additional packages as necessary)
RUN apt-get install -y --no-install-recommends \
    curl nodejs wget unzip vim git azure-cli jq build-essential libssl-dev libffi-dev python3 python3-venv python3-dev python3-pip

# cd into the user directory, download and unzip the github actions runner
RUN cd /home/docker &amp;&amp; mkdir actions-runner &amp;&amp; cd actions-runner \
    &amp;&amp; curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
    &amp;&amp; tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz

# install some additional dependencies
RUN chown -R docker ~docker &amp;&amp; /home/docker/actions-runner/bin/installdependencies.sh

# add over the start.sh script
ADD scripts/start.sh start.sh

# make the script executable
RUN chmod +x start.sh

# set the user to &quot;docker&quot; so all subsequent commands are run as the docker user
USER docker

# set the entrypoint to the start.sh script
ENTRYPOINT [&quot;/start.sh&quot;]
</code></pre>
<p>Helm values</p>
<pre><code>replicaCount: 1

image:
  repository: somecreg.azurecr.io/ghrunner
  pullPolicy: Always
  # tag: latest  

imagePullSecrets: []
nameOverride: &quot;&quot;
fullnameOverride: &quot;&quot;

env:
  GH_TOKEN: &quot;SET&quot;
  GH_OWNER: &quot;SET&quot;
  GH_REPOSITORY: &quot;SET&quot;
   
serviceAccount:
  create: true
  annotations: {}
  name: &quot;&quot;

podAnnotations: {}

podSecurityContext: {}


securityContext: {}

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: &quot;&quot;
  annotations: {}
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []


resources: {}

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}
tolerations: []
affinity: {}
</code></pre>
<p>Deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;hostedrunner.fullname&quot; . }}
  labels:
    {{- include &quot;hostedrunner.labels&quot; . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include &quot;hostedrunner.selectorLabels&quot; . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include &quot;hostedrunner.selectorLabels&quot; . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include &quot;hostedrunner.serviceAccountName&quot; . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: http
          # readinessProbe:
          #   httpGet:
          #     path: /
          #     port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
</code></pre>
<p>Console output for helm install
<a href="https://i.stack.imgur.com/bCJGv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bCJGv.png" alt="enter image description here" /></a></p>
<p>Helm command (tried both with set and set-string and values to get substituted correctly)</p>
<pre><code>helm install --set-string env.GH_TOKEN=&quot;$env:pat&quot; --set-string env.GH_OWNER=&quot;SomeOwner&quot; --set-string env.GH_REPOSITORY=&quot;aks-hostedrunner&quot; $deploymentName .helm/ --debug
</code></pre>
<p>I thought the helm variables might be passed as environment variables, but that's not the case. Any input is greatly appreciated</p>

jaspernygaard
<p>You can add and update your deployment template with</p>
<pre><code>env:
    {{- range $key, $val := .Values.env }}
    - name: {{ $key }}
      value: {{ $val }}
    {{- end }}
</code></pre>
<p>so it will add the env block into your deployment section and your <strong>shell</strong> script when will run inside the docker, it will be able to access the Environment variables</p>
<p>Deployment <strong>env</strong> example</p>
<pre><code>containers:
  - name: envar-demo-container
    image: &lt;Your Docker image&gt;
    env:
    - name: DEMO_GREETING
      value: &quot;Hello from the environment&quot;
    - name: DEMO_FAREWELL
      value: &quot;Such a sweet sorrow&quot;
</code></pre>
<p>Ref : <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#define-an-environment-variable-for-a-container" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#define-an-environment-variable-for-a-container</a></p>
<p>If you will implement above one those variables will get set as Environment variables and Docker will be able to access it(shell script inside the container).</p>
<p>You can also use the configmap and secret of Kubernetes to set values at <strong>Env</strong> level.</p>
