<p>I have a Kubernetes <code>Statefulset</code> and im using <code>envFrom</code> to add environment variables from ConfigMaps and Secrets, by defining configMapRefs and secretRefs in an 'extra-values.yaml' file and including that file in my <code>helm install</code> command.</p>
<p>The <code>Statefulset.yaml</code> snippet:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: StatefulSet
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
        - name: {{ .Chart.Name | lower}}
          envFrom:
          {{- if .Values.envFrom }}
          {{- toYaml .Values.envFrom | nindent 10}}
          {{- end }}
</code></pre>
<p>The values.yaml file has a single <code>envFrom:</code> line with no children, and the <code>extra-values.yaml</code> file contains the configMapRefs and secretRefs:</p>
<pre><code>envFrom:
- configMapRef:
    name: my-configmap-name
- configMapRef:
    name: another-configmap-name
- secretRef:
    name: my-secret-name
- secretRef:
    name: second-secret-name
</code></pre>
<p>The Helm install command:</p>
<pre><code>helm install myapp /some-folder/myapps-chart-folder -f extra-values.yaml
</code></pre>
<p>What I want to do is install <code>myapp</code> without the <code>extra-values.yaml</code> file, and then use the <code>kubectl patch</code> command to add the configMapRefs and secretRefs to the statefulset and its pods.</p>
<p>I can manually do a <code>kubectl edit statefulset</code> to make these changes, which will terminate and restart the pod(s) with the correct environment variables.</p>
<p>But I cannot for the life of me figure out the correct syntax and parameters for the <code>kubectl patch</code> command, despite hours of research, trial, and error, and repeated headbanging.  Help!</p>

Steve
<p>Thanks to <a href="https://stackoverflow.com/users/225016/mdaniel">mdaniel</a> for the answer, which contains the clue to what I was missing.  Basically, I completely overlooked the fact that the <code>containers</code> element is an <code>array</code> (because my <code>statefulset</code> only specified one container, duh).  In all of the <code>kubectl patch</code> command variations that I tried, I did not treat <code>containers</code> as an array, and never specified the container name, so <code>kubectl patch</code> never really had the correct information to act on.</p>
<p>So as suggested, the command that worked was something like this:</p>
<pre><code>kubectl patch statefulset my-statefulset -p '{&quot;spec&quot;: {&quot;template&quot;: {&quot;spec&quot;: {&quot;containers&quot;: [{&quot;name&quot;:&quot;the-container-name&quot;, &quot;envFrom&quot;: [{&quot;configMapRef&quot;:{&quot;name&quot;:&quot;my-configmap-name&quot;}}, {&quot;configMapRef&quot;:{&quot;name&quot;:&quot;another-configmap-name&quot;}}] }] }}}}'
</code></pre>
