<p>I have a general helm chart in my Kubernetes cluster taking a multiline text field with environment variables (identified by KEY=VALUE), translating them into the deployment.yaml like this:</p>
<p>Inside the Rancher dialog:
<a href="https://i.stack.imgur.com/ENJLM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ENJLM.png" alt="enter image description here" /></a></p>
<p>In the deployment.yaml:</p>
<pre><code>{{- if .Values.envAsMultiline }}
{{- range (split &quot;\n&quot; .Values.envAsMultiline) }}
            - name: &quot;{{ (split &quot;=&quot; .)._0 }}&quot;
              value: &quot;{{ (split &quot;=&quot; .)._1 }}&quot;
{{- end }}
{{- end }}
</code></pre>
<p>This works fine so far. But the problem now is: If I have a &quot;=&quot; in my environment variable (Like in the JAVA_OPTS above), it splits the environment variable value at the second &quot;=&quot; of the line:</p>
<blockquote>
<p>JAVA_OPTS=-Xms1024m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512m</p>
</blockquote>
<p>is translated to</p>
<blockquote>
<p>-Xms1024m -Xmx2048m -XX:MetaspaceSize</p>
</blockquote>
<p>The &quot;=256M -XX:MaxMetaspaceSize=512m&quot; is missing here.</p>
<p>How do I correct my deployment.yaml template accordingly?</p>

<p>Plan 1:</p>
<p>One of the simplest implementation methods</p>
<p>You can directly use the yaml file injection method, put the env part here as it is, so you can write the kv form value and the ref form value in the values in the required format.</p>
<p>As follows:</p>
<p><strong>values.yaml</strong></p>
<pre><code>env:
  - name: ENVIRONMENT1
    value: &quot;testABC&quot;
  - name: JAVA_OPTS
    value: &quot;-Xms1024m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M&quot;
  - name: TZ
    value: &quot;Europe/Berlin&quot;
</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>containers:
  - name: {{ .Chart.Name }}
    env:
      {{ toYaml .Values.env | nindent xxx }}
</code></pre>
<p>(ps: xxx --&gt; actual indent)</p>
<p>Plan 2:</p>
<p>Env is defined in the form of kv, which is rendered in an iterative manner</p>
<p><strong>values.yaml</strong></p>
<pre><code>env:
  ENVIRONMENT1: &quot;testABC&quot;
  JAVA_OPTS: &quot;-Xms1024m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M&quot;
  TZ: &quot;Europe/Berlin&quot;
</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>containers:
- name: {{ .Chart.Name }}
  env: 
    {{- range $k, $v := .Values.env }}
    - name: {{ $k | quote }}
      value: {{ $v | quote }}
    {{- end }}
</code></pre>
<p>Plan 3:</p>
<p>If you still need to follow your previous writing, then you can do this</p>
<p><strong>values.yaml</strong></p>
<pre><code>env: |
  ENVIRONMENT1=testABC
  JAVA_OPTS=-Xms1024m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M
  TZ=Europe/Berlin
</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>containers:
- name: {{ .Chart.Name }}
  {{- if .Values.env }}
  env:
  {{- range (split &quot;\n&quot; .Values.env) }}
  - name: {{ (split &quot;=&quot; .)._0 }}
    value: {{ . | trimPrefix (split &quot;=&quot; .)._0 | trimPrefix &quot;=&quot; | quote }}
  {{- end }}
  {{- end }}
</code></pre>
<p>output:</p>
<pre><code>env:
- name: ENVIRONMENT1
  value: &quot;testABC&quot;
- name: JAVA_OPTS
  value: &quot;-Xms1024m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M&quot;
- name: TZ
  value: &quot;Europe/Berlin&quot;

</code></pre>
