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?
CodePudding user response:
Every action in Kubernetes ca be invoked via rest API call. This is also stated as such in the docs.
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.
CodePudding user response:
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.