Cron工作作为程序还是本机K8S方式

时间:2019-04-16 19:48:13

标签: go kubernetes cron

我需要在K8S创建Cron作业。
有些作业每分钟运行一次,有些作业每5分钟(24/7)

此作业需要对某些组件运行rest调用(获取),并且 检查可用性,如果有什么问题(将)发送给其他系统的休息电话

要处理此任务,我目前看到两种方法

  1. 创建k8s cronjob -这是本地 k8s CRD,并使用shell scripthttps://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

PROS 正在使用K8S原生方法来处理此类问题

缺点-很难调试,记录调试等

  1. 创建k8s作业/ cronjob -执行运行 Golang程序,该程序将使用以下库作为cronjob

PROS -调试,记录等,https://github.com/robfig/cron

缺点-创建一些抽象...

任何建议,推荐,如果我需要对这些工作进行全面控制,那是更好的使用方法

1 个答案:

答案 0 :(得分:3)

I'd approach this problem in several steps.

First, write the program that does the REST calls, checks the result, maybe posts the alert, and exits. You can write this program in whatever language or toolkit you feel like. If you're comfortable in Go, great; I might pick Python myself; it'd be possible as a shell script, but probably more awkward than many alternatives. Build this program completely independently of Kubernetes. Test it as much as you need to convince yourself that it does what you want.

Once you've made the REST polling program work, and only then, build it into a Docker image; push it to a registry; and create a CronJob Kubernetes resource that runs it on a schedule.

Given how you've described the task, I wouldn't write a specialized program just to replicate Kubernetes' built-in scheduled-task runner. You could; I'd develop it the same way as above but use a Deployment instead of a CronJob; but probably the CronJob path is both simpler and more reliable.

相关问题