<p>I am using helm for k8s deployment and I need a cron job which will just access the url. I have written script and script works if I run it independently as a shell script task. Why the cron job is not able to run the script inside.</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: sampletemplaterelease-myapi
  labels:
    app.kubernetes.io/name: myapi
    helm.sh/chart: myapi-0.1.0
    app.kubernetes.io/instance: sampletemplaterelease
    app.kubernetes.io/version: "1.0"
    app.kubernetes.io/managed-by: Tiller
spec:
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/bash
            - -c
            - |
              accessTokenBody=$(curl -X POST -d "client_id=sample&amp;grant_type=sample&amp;username=sample&amp;password=sample&amp;override=true" https://sample.com/sample/sample)
              accessToken=$(jq -r  '.access_token' &lt;&lt;&lt; "${accessTokenBody}" )
              echo $accessToken
              sfSyncTriggerResult=$(curl -X POST -H "Content-Length: 0" -H "Authorization: Bearer $accessToken" https://sample.com/sample/sample)
              echo $sfSyncTriggerResult
              echo "${sfSyncTriggerResult}" | jq '.'
              errorCount=$(echo $sfSyncTriggerResult | jq '. | length')
              echo "Total Number Of Errors"
              echo $errorCount
              if [ "$errorCount" -gt 0 ]
                  then
                      echo "not working, exiting"
                      exit 1
                      break
              else
                      echo "Sync triggered successfully"
                  fi
          restartPolicy: OnFailure
</code></pre>

<blockquote>
  <p>kubectl logs podname:</p>
</blockquote>

<pre><code>% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1183    0  1053  100   130   1193    147 --:--:-- --:--:-- --:--:--  1339
/bin/bash: line 1: jq: command not found



  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

/bin/bash: line 7: jq: command not found
/bin/bash: line 8: jq: command not found
Total Number Of Errors

Sync triggered successfully
/bin/bash: line 11: [: : integer expression expected
</code></pre>

Vatan Soni
<p>You can do it by using any image that has <code>jq</code> or if you install <code>jq</code> inside of the container. So, one way i tried is using <code>alpine</code> as the container image instead of <code>busybox</code> and then installed <code>jq</code> in it. See the followings:</p>

<pre><code>spec:
  template:
    spec:
      containers:
      - name: hello
        image: alpine
        args:
        - sh
        - -c
        - |
          apk add --no-cache jq
          &lt;do_what_you_need&gt;
</code></pre>
