2019-04-16 19:48
浏览 90


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,

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 ,

CONS - create some abstraction …

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

图片转代码服务由CSDN问答提供 功能建议

一些作业每分钟运行一次,其中一些作业每分钟运行一次 5分钟(24/7)

此作业需要对某些组件运行rest调用(获取),并 检查可用性,如果有问题(对其他组件进行发布) 系统


  1. 创建k8s cronjob - 本地 k8s CRD并为其使用 shell脚本

    > PROS 正在使用K8S本地方法来处理此类问题

    CONS -很难调试,记录调试等 \ n

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

      PROS -调试,日志记录等,

      CONS -创建一些抽象……


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题