<p>Below is how I am using kunbernetes on google.</p>

<p>I have one node application let's say <strong>Book-portal</strong>.</p>

<p>node app is using <strong>environment variables for configurations</strong>.</p>

<p><strong>Step1:</strong> I created docker file and pushed</p>

<pre><code>gcr.io/&lt;project-id&gt;/book-portal:v1
</code></pre>

<p><strong>Step2:</strong> deployed with following commands</p>

<pre><code>kubectl run book-portal --image=gcr.io/&lt;project-id&gt;/book-portal:v1 --port=5555 --env ENV_VAR_KEY1=value1 --env ENV_VAR_KEY2=value2 --env ENV_VAR_KEY3=value3
</code></pre>

<p><strong>Step3:</strong></p>

<pre><code>kubectl expose deployment book-portal --type="LoadBalancer"
</code></pre>

<p><strong>Step4:</strong> Get public ip with </p>

<pre><code>kubectl get services book-portal
</code></pre>

<p>now assume I added new features and new configurations in next release.</p>

<p><strong>So to roll out new version v2</strong></p>

<p><strong>Step1:</strong> I created docker file and pushed</p>

<pre><code>gcr.io/&lt;project-id&gt;/book-portal:v2
</code></pre>

<p><strong>Step2:</strong> Edit deployment</p>

<pre><code>kubectl edit deployment book-portal

---------------yaml---------------
...
    spec:
      replicas: 1
      selector:
        matchLabels:
          run: book-portal
      strategy:
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            run: book-portal
        spec:
          containers:
          - env:
            - name: ENV_VAR_KEY1
              value: value1
            - name: ENV_VAR_KEY2
              value: value2
            - name: ENV_VAR_KEY3
              value: value3
            image: gcr.io/&lt;project-id&gt;/book-portal:v1
            imagePullPolicy: IfNotPresent
            name: book-portal
...
----------------------------------
</code></pre>

<p>I am successfully able to change </p>

<pre><code>image:gcr.io/&lt;project-id&gt;/book-portal:v1 
</code></pre>

<p>to</p>

<pre><code>image:gcr.io/&lt;project-id&gt;/book-portal:v2 
</code></pre>

<p>But I can not add/change environment variables</p>

<pre><code>          - env:
            - name: ENV_VAR_KEY1
              value: value1
            - name: ENV_VAR_KEY2
              value: value2
            - name: ENV_VAR_KEY3
              value: value3
            - name: ENV_VAR_KEY4
              value: value4
</code></pre>

<ol>
<li>Can anyone guide with what is best practices to pass configurations
in node app on kubernetes? </li>
<li>how should I handle environment variable
changes during rolling updates?</li>
</ol>

<p>I think your best bet is to use configmaps in k8s and then change you pod template to get env variable values from the configmap see <a href="http://kubernetes.io/docs/user-guide/configmap/" rel="noreferrer">Consuming ConfigMap in pods</a></p>

<p>edit: I appologize I put the wrong link here. I have updated but for the TL;DR
you can do the following.</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
 name: special-config
namespace: default
data:
 special.how: very
 special.type: charm
</code></pre>

<p>and then pod usage can look like this.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: dapi-test-pod
spec:
  containers:
  - name: test-container
    image: gcr.io/google_containers/busybox
    command: [ "/bin/sh", "-c", "env" ]
    env:
      - name: SPECIAL_LEVEL_KEY
        valueFrom:
          configMapKeyRef:
            name: special-config
            key: special.how
      - name: SPECIAL_TYPE_KEY
        valueFrom:
          configMapKeyRef:
            name: special-config
            key: special.type
  restartPolicy: Never
</code></pre>
