Creating a Cron Job in K8S
Creating a Cron Job
Cron jobs require a config file. This example cron job config .spec file prints the current time and a hello message every minute:
application/job/cronjob.yaml |
|---|
|
Run the example cron job by downloading the example file and then running this command:
$ kubectl create -f ./cronjob.yaml
cronjob "hello" created
Alternatively, you can use kubectl run to create a cron job without writing a full config:
$ kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello from the Kubernetes cluster"
cronjob "hello" created
After creating the cron job, get its status using this command:
$ kubectl get cronjob hello
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
hello */1 * * * * False 0 <none>
As you can see from the results of the command, the cron job has not scheduled or run any jobs yet. Watch for the job to be created in around one minute:
$ kubectl get jobs --watch
NAME DESIRED SUCCESSFUL AGE
hello-4111706356 1 1 2s
Now you’ve seen one running job scheduled by the “hello” cron job. You can stop watching the job and view the cron job again to see that it scheduled the job:
$ kubectl get cronjob hello
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
hello */1 * * * * False 0 Mon, 29 Aug 2016 14:34:00 -0700
You should see that the cron job “hello” successfully scheduled a job at the time specified in LAST-SCHEDULE. There are currently 0 active jobs, meaning that the job has completed or failed.
Now, find the pods that the last scheduled job created and view the standard output of one of the pods. Note that the job name and pod name are different.
# Replace "hello-4111706356" with the job name in your system
$ pods=$(kubectl get pods --selector=job-name=hello-4111706356 --output=jsonpath={.items..metadata.name})
$ echo $pods
hello-4111706356-o9qcm
$ kubectl logs $pods
Mon Aug 29 21:34:09 UTC 2016
Hello from the Kubernetes cluster
https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/
Creating a Cron Job in K8S的更多相关文章
- K8S从入门到放弃系列-(1)环境初始化
一.系统规划 主机名 IP 组件 k8s-master01 10.10.0.18 etcd.kube-apiserver.kube-controller-manager.kube-schedu ...
- Quartz 2.2.x CronTrigger Tutorial
http://www.quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/crontrigger.html Introduction c ...
- kubernetes secret 和 serviceaccount删除
背景 今天通过配置创建了一个serviceaccounts和secret,后面由于某种原因想再次创建发现已存在一个serviceaccounts和rolebindings.rbac.authoriza ...
- k8s 执行 ingress yaml 文件报错: error when creating "ingress-myapp.yaml": Internal error occurred: failed calling webhook
k8s 执行 ingress yaml 文件报错:错误如下: [root@k8s-master01 baremetal]# kubectl apply -f ingress-test.yaml Err ...
- k8s的基本使用
一.kubectl的命令参数 1)kubectl 能使用的命令.即查看帮助 [root@k8s6 ~]# kubectl kubectl controls the Kubernetes cluster ...
- [k8s]Docker 用户使用 kubectl 命令指南-unkown排错(kubelet端口解析)
参考:https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/ https://k8smeetup.github.io/docs/user-g ...
- docker+k8s基础篇二
Docker+K8s基础篇(二) docker的资源控制 A:docker的资源限制 Kubernetes的基础篇 A:DevOps的介绍 B:Kubernetes的架构概述 C:Kubernetes ...
- K8S(16)集成实战-使用spinnaker进行自动化部署
K8s集成实战-使用spinnaker进行自动化部署 1 spinnaker概述和选型 1.1 概述 1.1.1 主要功能 Spinnaker是一个开源的多云持续交付平台,提供快速.可靠.稳定的软件变 ...
- 搭建docker私有仓库,建立k8s集群
服务器IP角色分布 192.168.5.2 etcd server 192.168.5.2 kubernetes master 192.168.5.3 kubernetes node 192.168. ...
随机推荐
- 微软职位内部推荐-Principal Group Program Manager
微软近期Open的职位: Standard job title: Principal Group Program Manager Discipline: Program Management Prod ...
- Scrum立会报告+燃尽图(十一月十八日总第二十六次):功能开发与讨论贡献分配规则
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...
- Alpha发布——视频博客
1.视频链接 视频上传至优酷自频道,地址链接:https://v.youku.com/v_show/id_XMzg5MzQ4MzM2MA==.html?spm=a2h0k.11417342.sores ...
- 团队开发--NABCD
团队成员介绍: 李青:绝对的技术控,团队中扮演“猪”的角色,勤干肯干,是整个团队的主心骨,课上紧跟老师的步伐,下课谨遵老师的指令,课堂效率高,他的编程格言“没有编不出来的程序,只有解决不了的bug”. ...
- HDU 5661 Claris and XOR 贪心
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- Alpha - Postmortem
Alpha - Postmortem NewTeam 2017/11/18 目录 设想和目标 计划 资源 变更管理 设计/实现 测试/发布 团队角色.管理.合作 总结 设想和目标 返回目录 1. 软件 ...
- 使用selenium遍历frame中的表单信息 ;
遍历frame中的表单 : package webDriverPro; import java.util.List; import java.util.regex.Matcher; import ja ...
- VC的常用调试方法
前言 VS是非常强大的IDE,所以掌握VSVC的常用方法,将会使得我们找出问题解决问题事半功倍. 目录 VSVC的常用调试方法 前言 1. Watch窗口查看伪变量 2. 查看指针指向的一序列值 3. ...
- Halcon 笔记2 Blob分析
1. 数组操作 2. 可视化-更新窗口 (1)单步模式-总是:则可以自动显示图像: (2)单步模式-从不:需要调用显示函数才能显示图像. (3)单步模式-清空显示:将原图清除,再显示新图 3. 图像处 ...
- Android性能测试工具APT
APT源码地址:https://code.csdn.net/Tencent/apt APT,Android Performance Testing Tools,适用于开发自测和定位性能瓶颈,帮助测试人 ...