<p>I am using a Kubernetes Cronjob to run period database restores and post restore scripts which runs against the target environment which include tasks such as working with the database, redis, and file system.</p>

<p>The issue I am facing is that I have to re-define all the environment variables I use in my Deployment within the Cronjob (E.g., <code>DATABASE_NAME</code>, <code>DATABASE_PASSWORD</code>, <code>REDIS_HOST</code> etc.).</p>

<p>While repeating all the environment variables works, it is error prone as I have already forgotten to update the jobs which results in me having to re-run the entire process which takes 2-4 hours to run depending on what environment.</p>

<p><strong>Is there a way to reference an existing <code>Deployment</code> and re-use the defined environment variables within my Cronjob?</strong> </p>

leeman24
<p>You can use 'kind: PodPreset' object to define and inject comman env variables  into multiple kuberentes objects like deployments/statefulsets/pods/replicasets etc.</p>

<p>Follow the link for help --> <a href="https://kubernetes.io/docs/tasks/inject-data-application/podpreset/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/podpreset/</a></p>
