Should I use configMap for every environment variable?

南笙酒味 提交于 2019-12-06 02:58:12

Aside from the points about separation of config from pods, one advantage of a ConfigMap is it lets you make the values of the variables accessible to other Pods or apps that are not necessarily part of your chart.

It does add a little extra complexity though and there can be a large element of preference about when to use a ConfigMap. Since your ConfigMap keys are the names of the environment variables you could simplify your Deployment a little by using 'envFrom'

It would work even if you don't use a configmap, but it has some advantages:

  • You can update the values at runtime, without updating a deployment. Which means you might not need to restart your application (pods). If you don't use a config map, everytime you update the value, your application (or pod) will be recreated.
  • Separation of concerns, i.e. deployment configuration and external values separated

I feel like this is largely a matter of taste; but I've generally been avoiding ConfigMaps for cases like these.

env:
{{- range $k, $v := .Values.environmentVariables }}
  - name: {{ quote $k }}
    value: {{ quote $v }}
{{- end }}

You generally want a single source of truth and Helm can be that: you don't want to be in a situation where someone has edited a ConfigMap outside of Helm and a redeployment breaks local changes. So there's not a lot of value in a ConfigMap being "more editable" than a Deployment spec.

In principle (as @Hazim notes) you can update a ConfigMap contents without restarting a container, but that intrinsically can't update environment variables in running containers, and restarting containers is so routine that doing it once shouldn't matter much.

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