Reputation: 181
I have bunch of cron jobs that sit in an EKS cluster and would like to trigger them via HTTP call. Does such API exist from Kubernetes? If not, what else can be done?
Upvotes: 2
Views: 4515
Reputation: 83
For anyone interested to sent HTTP requests from a pod to control the cluster like a manual trigger for a cronjob, you just need to setup a role and a rolebinding for a service account for that pod/deployment. After that you can authenticate the requests using the bearer token at /var/run/secrets/kubernetes.io/serviceaccount/token
Upvotes: 0
Reputation: 20457
Every action in Kubernetes ca be invoked via rest API call. This is also stated as such in the docs.
There is a full API reference for the Kubernetes API you can review.
In fact, kubectl is using http under the hood. You can see those http calls by using the v
flag with some verbosity level. For example:
$ kubectl get pods -v=6
I1206 00:06:33.591871 19308 loader.go:372] Config loaded from file: /home/blue/.kube/config
I1206 00:06:33.826009 19308 round_trippers.go:454] GET https://mycluster.azmk8s.io:443/api?timeout=32s 200 OK in 233 milliseconds
...
So you could check out the command you need by looking how kubectl does it. But given the fact that kubectl does use http, it's maybe easier to just use kubectl directly.
Upvotes: 3
Reputation: 763
A cron job by definition is triggered by a time event (every hour, every month).
If you want to to force a trigger you can use:
kubectl create job --from=cronjob/<cron-job-name> <job-name> -n <namespace>
This is using the Kube Api which is a RESTful service, so I think it's fulfilling your request.
Upvotes: 1