<p>In kubernetes I have a secret defined, and in my deploy-templates YAML files, I have that secret set as ${mySecret}.</p>
<p>I am trying to create a CronJob that uses the following CURL to run the Job with the header info defined in the secret. No matter what I do, the ${mySecret} doesn't seem to get turned into the correct information.</p>
<p>Do I have to define it some other way in the YAML?</p>
<pre><code>apiVersion: myjob/v1
kind: CronJob
metadata:
  name: {{ .Values.name }}-cronjobs
spec:
  schedule: &quot;0 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          initContainers:
          - name: my-job
            image: curlimages/curl
            command: [&quot;sh&quot;, &quot;-c&quot;, &quot;curl --location --request POST \&quot;http://myservice:8080/api/endpoint\&quot; --header \&quot;my-secret: ${mySecret}\&quot;&quot;]

</code></pre>
<p>Tried to use ${} in a yaml-based curl command. I expected the value to be parsed and run the job correctly. In reality, I get a BAD REQUEST error from the job every hour.</p>

Cody M.
<p>You have to add the secret to the env-vars of your container.
Suppose you have a <code>my-secret</code> secret:</p>
<pre><code>apiVersion: v1
metadata:
  name: my-secret
type: Opaque
data:
  THE_SECRET: dG9wU2VjcmV0MTIz
</code></pre>
<p>Then you can reference the value in <code>THE_SECRET</code> in your cron-job like this:</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: {{ .Values.name }}-cronjobs
spec:
  schedule: &quot;0 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: my-job
            image: curlimages/curl
            command: [&quot;sh&quot;, &quot;-c&quot;, &quot;curl --location --request POST \&quot;http://myservice:8080/api/endpoint\&quot; --header \&quot;my-secret: ${THE_SECRET}\&quot;&quot;]
            envFrom:
            - secretRef:
                name: my-secret
            - secretRef:
                name: other-secret
</code></pre>
