Kubernetes Deployment RollingUpdate does not add new environment variable

9/16/2016

Im on kubernetes 1.3.5, we are using Deployments with rollingupdates to update the pods in our cluster. However, on rollingupdate, the newly added environment variable never gets added to the pod, is it by design ? what are the ways to get around that ?

Following is the sample deployment yaml files. Basically the deployment was deployed with first version then we updated the yaml with newly added env variable NEW_KEY and basically run through the rolling updated. But the new env does not show up in the PODS.

first version yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: APP_NAME-deployment labels: name: APP_NAME environment: DEV spec: revisionHistoryLimit: 2 strategy: type: RollingUpdate replicas: 2 template: metadata: labels: name: APP_NAME environment: DEV spec: containers: - name: APP_NAME image: repo.app_name:latest env: - name: NODE_ENV value: 'development' - name: APP_KEY value: '123'

updated yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: APP_NAME-deployment labels: name: APP_NAME environment: DEV spec: revisionHistoryLimit: 2 strategy: type: RollingUpdate replicas: 2 template: metadata: labels: name: APP_NAME environment: DEV spec: containers: - name: APP_NAME image: repo.app_name:latest env: - name: NODE_ENV value: 'development' - name: APP_KEY value: '123' - name: NEW_KEY value: 'new'

-- Eatdoku
kubernetes

1 Answer

5/16/2019

You can store the env variable in either a ConfigMap or secretKeyRef. For a ConfigMap you would do:

      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              name: node_env
              key: node.dev

Or with a secretKeyRef:

      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            secretKeyRef:
              name: node_env
              key: node.dev
-- William Ross
Source: StackOverflow