ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-04-22 11:47:41  阅读:651  来源: 互联网

标签:kubectl cronjob Kubernetes manually daily cron job


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: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-job-em-

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

  

标签:kubectl,cronjob,Kubernetes,manually,daily,cron,job
来源: https://www.cnblogs.com/weifeng1463/p/10749220.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有