<p>I create my helm chart manually</p>
<pre><code>├── Chart.yaml
├── Dockerfile
├── locustfile.py
├── requirements.in
├── requirements.txt
├── templates
│   ├── ConfigMap.yaml
│   └── deployment.yaml
└── values.yaml
</code></pre>
<p>I install it with the following command</p>
<pre><code>helm upgrade --install loadgenerator . 
</code></pre>
<p>the configmap is not applied and therefore the pods do not start
in the description of the pod such an error</p>
<pre><code>Events:
  Type     Reason         Age                    From               Message
  ----     ------         ----                   ----               -------
  Normal   Scheduled      47m                    default-scheduler  Successfully assigned default/loadgenerator-66c46bd489-5rm8v to minikube
  Warning  Failed         45m (x12 over 47m)     kubelet            Error: InvalidImageName
  Warning  InspectFailed  2m17s (x214 over 47m)  kubelet            Failed to apply default image tag &quot;$(image_init_container)&quot;: couldn't parse image reference &quot;$(image_init_container)&quot;: invalid reference format
</code></pre>
<p>configmap</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: app
data:
  image_init_container: &quot;busybox:latest&quot;
  image_app: &quot;loadgenerator&quot;
  namespace: default
  env: prod
</code></pre>
<p>Deployment</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: loadgenerator  
spec:
  selector:
    matchLabels:
      app: loadgenerator
  replicas: 1
  template:
    metadata:
      labels:
        app: loadgenerator        
      annotations:
        sidecar.istio.io/rewriteAppHTTPProbers: &quot;true&quot;
    spec:
      serviceAccountName: default
      terminationGracePeriodSeconds: 5
      restartPolicy: Always
      securityContext:
        fsGroup: 1000
        runAsGroup: 1000
        runAsNonRoot: true
        runAsUser: 1000
      initContainers:
      - command:
        - /bin/sh
        - -exc
        - |
          echo &quot;Init container pinging frontend: ${FRONTEND_ADDR}...&quot;
          STATUSCODE=$(wget --server-response http://${FRONTEND_ADDR} 2&gt;&amp;1 | awk '/^  HTTP/{print $2}')
          if test $STATUSCODE -ne 200; then
              echo &quot;Error: Could not reach frontend - Status code: ${STATUSCODE}&quot;
              exit 1
          fi
        name: frontend-check
        image: $(image_init_container)
        envFrom:
          - configMapRef:
              name: app
        env:
        - name: FRONTEND_ADDR
          value: &quot;frontend:80&quot;
      containers:
      - name: main
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
              - all
          privileged: false
          readOnlyRootFilesystem: true
        image: $(image_app)
        envFrom:
          - configMapRef:
              name: app
        env:
        - name: FRONTEND_ADDR
          value: &quot;frontend:80&quot;
        - name: USERS
          value: &quot;10&quot;
        resources:
          requests:
            cpu: 300m
            memory: 256Mi
          limits:
            cpu: 500m
            memory: 512Mi
</code></pre>
<p>my task is to write a help chart while the environment variables should be in configmap.
why is configmap not applied? how to create it correctly and where do I make a mistake?</p>

Iceforest
<p>The problem isn't with your <code>ConfigMap</code> not getting injected in the <code>Deployment</code>. As the error mentions, you chart doesn't understand the <code>$(image_init_container)</code> <strong>value of image because rendered manifest is consuming it literally</strong>. Same would be the case when it reaches to <code>$(image_app)</code>.</p>
<p>Helm chart renders the templates into actual Kubernetes manifests and passes them to the API server. Once executed, the resultant <code>Pod</code>s of the <code>Deployment</code> will contain the environment variables as defined in the <code>ConfigMap</code>. <strong>You need to specify the image before the rendering step, not after the chart gets executed by the api-server</strong>.</p>
<p>If you want to dynamically set the image name, then define variables in <code>values.yml</code> and reference them in <code>Deployment</code> template. Here's simple example:</p>
<pre><code># values.yml
image:
  name: loadgenerator
  tag: latest
</code></pre>
<hr />
<pre><code> # deployment.yml
 containers:
  - name: main
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop:
          - all
      privileged: false
      readOnlyRootFilesystem: true
    image: {{ .Values.image.name }}:{{ .Values.image.tag }}
</code></pre>
