I am trying to use a k8s cron job to schedule API calls to a service. I am new to k8s cron jobs. The service requires an Auth token in the request header for authorization. That auth token can be retrieved from Token service(another service) call. Is it possible to fetch from the cURL response by first calling the Token service from the cron job and then calling the actual service. Any help...
Also the Token service needs some client details for generating the auth token, so is there any way to feed the details to the job every time it gets triggered via cron job.
Here is what I want to achieve:
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
suspend: false
backoffLimit: 2
template:
spec:
containers:
- name: hello
image: nightfury1204/alpine-curl
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- curl http://TokenService {get response data, use token in the next call}
- curl http://TaskService -H 'Authorization:Bearer <above_token>'
restartPolicy: OnFailure
Have searched through some documentations and gone through some stack overflow questions, but did not get any reference on the same.