0

This may belong in sys admin, but as I was preparing a kubectl apply -f configmap.yaml, I was curious if there is an official way of defining and getting env vars from the local .bash_profile or .zprofile.

For example,

apiVersion: v1
kind: ConfigMap
metadata:
  name: appconfig
  labels:
    app: app
data:
  DATA_POINT: ${GET_DATA_POINT_FROM_LOCAL_ENV_VAR} <-- Is there an official way to inject/retrieve locally defined env vars when I kubectl apply -f?

I did my obligatory search through kubernetes documentation and google. No luck.

Does anyone know an official way to inject/retrieve locally defined env vars into the configmap.yaml when I kubectl apply -f?

Mykel
  • 1,355
  • 15
  • 25
  • 1
    No OOB mechanism, check proposed solutions here https://stackoverflow.com/questions/48296082/how-to-set-dynamic-values-with-kubernetes-yaml-file – Olesya Bolobova Nov 24 '20 at 20:40
  • @OlesyaBolobova I figured. Thanks for the link. – Mykel Nov 24 '20 at 20:52
  • @Mykel Could you write down your solution if a form of an answer? It would be more visible for the rest of the community. – Wytrzymały Wiktor Nov 25 '20 at 09:29
  • @Mykel Can you help with your proposed solution ? I also need something like this – avinashjha Nov 25 '20 at 10:01
  • 1
    While the linked question says it's about Deployments, its answers are around ways to manipulate the YAML files and will work with any Kubernetes object. A templating tool like [Helm](https://helm.sh) can also help here (it will not read the calling environment but has other ways to pass in deploy-time configuration). – David Maze Nov 25 '20 at 11:42
  • @DavidMaze Can you elaborate about "other ways to pass in deploy-time configuration?" – Mykel Nov 25 '20 at 17:36
  • 1
    In the Helm documentation there's a section on [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). You can provide a YAML file or command-line options with settings, and the YAML files allow templating syntax to fill in values from these settings. – David Maze Nov 25 '20 at 19:34

0 Answers0