Kubernetes cronjob args with env vars Kubernetes cronjob args with env vars kubernetes kubernetes

Kubernetes cronjob args with env vars


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

apiVersion: batch/v1beta1kind: CronJobmetadata:  name: appspec:  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

You can test the output yaml by doing:

kubectl apply -f job.yaml -o yaml --dry-run

which shows the final output is fine

apiVersion: batch/v1beta1kind: CronJobmetadata:  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: defaultspec:  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

I tested this with https://requestbin.fullcontact.com/ and the bearer token was passed without issue