Schedule Cronjobs in Kubernetes
![Abishek Kafle](https://cdn.hashnode.com/res/hashnode/image/upload/v1726213286603/488379c0-3bf8-45ec-afb8-db5ac8509d5c.jpeg)
1 min read
![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729013210536/d775c58b-d758-47b6-b179-f2b2a23da527.png)
Tasks
Create a cronjob named
xfusion
.Set its schedule to something like
*/7 * * * *
. You can set any schedule for now.Name the container
cron-xfusion
.Utilize the
httpd
image withlatest tag
(specify ashttpd:latest
).Execute the dummy command
echo Welcome to xfusioncorp!
.Ensure the restart policy is
OnFailure
.
Steps
Create a manifest file
cronjob.yaml
using given details.apiVersion: batch/v1 kind: CronJob metadata: name: xfusion spec: schedule: "*/7 * * * *" jobTemplate: spec: template: spec: restartPolicy: OnFailure containers: - name: cron-xfusion image: httpd:latest command: ["echo", "Welcome to xfusioncorp!"]
cat <<EOF > cronjob.yaml apiVersion: batch/v1 kind: CronJob metadata: name: xfusion spec: schedule: "*/7 * * * *" jobTemplate: spec: template: spec: restartPolicy: OnFailure containers: - name: cron-xfusion image: httpd:latest command: ["echo", "Welcome to xfusioncorp!"] EOF
Now apply the yaml manifest file.
k apply -f cronjob.yaml
- We can also use
kubectl apply -f cronjob.yaml
too.
- We can also use
Let’s get the result.
k get cronjob -o wide
Describe the cronjob now.
k describe cronjob
#cronjob #k8s #kubernetes #happylearning
0
Subscribe to my newsletter
Read articles from Abishek Kafle directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
![Abishek Kafle](https://cdn.hashnode.com/res/hashnode/image/upload/v1726213286603/488379c0-3bf8-45ec-afb8-db5ac8509d5c.jpeg)
Abishek Kafle
Abishek Kafle
Infosec Poet and CAP-certified DevOps/SecOps Engineer, passionate about security, creativity, and continuous learning.