kubernetes Deployment. how to change container environment variables for rolling updates?

天涯浪子 提交于 2019-12-04 19:23:37

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 Consuming ConfigMap in pods

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

apiVersion: v1
kind: ConfigMap
metadata:
 name: special-config
namespace: default
data:
 special.how: very
 special.type: charm

and then pod usage can look like this.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!