dongqiao6445 2019-04-16 19:48
浏览 90
已采纳

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

I need to create a Cron jobs at K8S.
some jobs runs every minute , some of them every 5 minutes (24/7)

This jobs need to run rest call (get) to some components and to check the availability and if something is wrong (post) a rest call to other system

To handle this task I currently see two approaches

  1. Create k8s cronjob - which is native k8s CRD and use shell script for it, https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

PROS is using K8S native way to handle such issue

CONS - very hard to debug, logs debug etc

  1. Create k8s job/cronjob - which execute run a Golang program that will do use following library as cronjob

PROS - debug , logging etc , https://github.com/robfig/cron

CONS - create some abstraction …

Any suggestion, recommendation which is better approach to use If I need a full control on those jobs

  • 写回答

1条回答 默认 最新

  • duanjing7459 2019-04-16 23:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境