How to add env vars into k8s job.yaml dynamically?

Viewed 64

I have store my env vars in aws secret manger.In CD pipeline I will read this env from secret manager and store into env.yaml once it is available in env.yaml,i want to render it to kubernetes job.yaml file. How to render env var from env.yaml to my k8s job.yaml ??

1 Answers

Not sure how your env.yaml structure is however i would suggest adding the secret as the kubenetes secret.

You can mount the secret to any job running into the K8s.

If you want to parse it from one YAML to add it into the another YAML file you can use the tool Yq to parse the values.

Example:

---
maindata:
  data1:
    name: jack
  data2:
    name: reacher

run command

yq eval '.maindata.*.name' env.yaml

will output

- jack
- teacher

You can save output or write it to variable and use it.

Related