How to trigger a Kubernetes cronjob manually-手动触发一个cronjob

33 篇文章 7 订阅

What should you do when you’ve developed and installed a cron job for your Kubernetes application, and you need to test it? When writing classic cron jobs in Unix, it’s obvious how to test the job- just manually run the command specified in the cron file. However, it’s not as obvious how to do this in Kubernetes.

We encountered this problem not long ago while setting up a daily PostgreSQL backup job for one of our projects. Triggering a CronJob manually was difficult or impossible in older versions of Kubernetes, but since K8S 1.10 it can be done like this:

kubectl create job --from=cronjob/<name of cronjob> <name of job>

For example, if the name of your cronjob is “pgdump”, then you might run:

kubectl create job --from=cronjob/pgdump pgdump-manual-001

To see a list of cron jobs, run “kubectl get cronjob”.

The job creates a pod that runs to completion. You can review the command output by using kubectl to show pod logs.

Further reading

The official Kubernetes docs are here: Kubectl Reference Docs

The thread discussing this Kubernetes feature is here: https://github.com/kubernetes/kubernetes/issues/47538

实例配置:

[root@compass-user-hd-master3]:~# kubectl create job tmp-daily-report-job-02 --from=cronjob/job-1119051325-app-v1-0  -n data-infra

NAME                      AGE

tmp-daily-report-job-02   0s

[root@compass-user-hd-master3]:~# kubectl get pod  -n data-infra -o wide

tmp-daily-report-job-02-49mbv                 1/1       Running            0          6s        192.168.73.194   kube-node-192-168-0-246

  

转载至https://www.cnblogs.com/weifeng1463/p/10749220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值