<p>I'm trying to execute a <code>curl</code> command inside a container in <code>gke</code>.</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: app
            image: appropriate/curl
            env:
            - name: URL
              value: "https://app.com"
            - name: PASSWORD
              value: "pass"
            args: ["-vk", "-H", "\"Authorization: Bearer $(PASSWORD)\"", "$(URL)"]
          restartPolicy: OnFailure
</code></pre>

<p>Error:</p>

<pre><code>curl: option -vk -H "Authorization: Bearer pass" https://app.com: is unknown
</code></pre>

<p>I just can't find out how to execute the <code>curl</code> with the <code>args</code> field using environment variables.</p>

<p>This curl command works in my pc.<br>
What am I doing wrong?<br>
How can I integrate env vars with container curl command args?</p>

<p>You don't need to wrap the auth header in quotes, kubernetes will do that for you.</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: app
            image: appropriate/curl
            env:
            - name: URL
              value: "app.com"
            - name: PASSWORD
              value: "pass"
            args: ["-vk", "-H", "Authorization: Bearer $(PASSWORD)", "$(URL)"]
          restartPolicy: OnFailure
</code></pre>

<p>You can test the output yaml by doing:</p>

<pre><code>kubectl apply -f job.yaml -o yaml --dry-run
</code></pre>

<p>which shows the final output is fine</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"batch/v1beta1","kind":"CronJob","metadata":{"annotations":{},"name":"app","namespace":"default"},"spec":{"jobTemplate":{"spec":{"template":{"spec":{"containers":[{"args":["-vk","-H","Authorization: Bearer $(PASSWORD)","$(URL)"],"env":[{"name":"URL","value":"https://app.com"},{"name":"PASSWORD","value":"pass"}],"image":"appropriate/curl","name":"app"}],"restartPolicy":"OnFailure"}}}},"schedule":"* * * * *"}}
  name: app
  namespace: default
spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - args:
            - -vk
            - -H
            - 'Authorization: Bearer $(PASSWORD)'
            - $(URL)
            env:
            - name: URL
              value: https://app.com
            - name: PASSWORD
              value: pass
            image: appropriate/curl
            name: app
          restartPolicy: OnFailure
</code></pre>

<p>I tested this with <a href="https://requestbin.fullcontact.com/" rel="noreferrer">https://requestbin.fullcontact.com/</a> and the bearer token was passed without issue</p>
