Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

58 of kubernetes practice: CronJob

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

One: brief introduction

CronJob is a scheduled task, which is similar to the crontab of Linux system, which runs a specified task in a specified period of time.

1. Run only once at a given point in time

two。 Run periodically at a given point in time

II: CronJob definition

1.spec.schedule specifies the running period of the task in the same format as Cron

2.spec.jobTemplate specifies the tasks to be run in the same format as Job

3.spec.startingDeadlineSeconds specifies a deadline for the task to start

4.spec.concurrencyPolicy specifies the concurrency strategy for tasks, and supports three options: Allow, Forbid and Replace

Three: examples

Click (here) to collapse or open

ApiVersion: batch/v1beta1

Kind: CronJob

Metadata:

Name: hello

Spec:

Schedule: "* / 1 *"

JobTemplate:

Spec:

Template:

Spec:

Containers:

-name: hello

Image: busybox

Args:

-/ bin/sh

-- c

-date; echo Hello from the Kubernetes cluster

RestartPolicy: OnFailure1. Kubectl create-f croJob.yaml

2. Kubectl get cronjob hello

3.kubectl get jobs-watch monitors the implementation of job

Four: other

1.Cron Job probably creates a Job object during each scheduled run time. We say this probably because two Job may be created in a particular environment, or none of the Job may be created. We try to reduce this situation, but we can't avoid it completely. Therefore, creating a Job operation should be idempotent.

Based on the parallelism of the Pod it creates, Job is responsible for retrying the creation of the Pod and determining the success or failure of this set of Pod. Cron Job will not check the Pod at all.

two。 Once you no longer need Cron Job, you can simply delete it using the kubectl command: kubectl delete cronjob hello. This will terminate the Job being created. However, running Job will not be terminated and Job or their Pod will not be deleted. To clean up those Job and Pod, you need to list all the Job created by that Cron Job, and then delete them.

3. Once the Job is deleted, the Pod created by Job is also deleted. Note that all Job created by the Cron Job with the name "hello" is named with the prefix string "hello-". If you want to delete all Job in the current Namespace, you can delete them immediately with the command kubectl delete jobs-- all.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report