Found 0 result in total
Content is empty
If you don't find the content you expect, please try another search term
Last updated:2021-04-14 15:43:54
This topic describes how to manage the lifecycle of a Kubernetes-native CronJob, for example, how to create, configure, and delete a CronJob.
To create a CronJob, perform the following steps:
The configuration items are described as follows:
Indicates whether a newly created job can concurrently run with a running job. The following three policies are available:
The default policy is Allow.
Indicates when the CronJob runs. Enter a five-field Cron expression in the following format: Minute Hour Day Month Week. For example, /1 * indicates that a job runs every hour.
# Five-field Cron expression
# ——Minute(0 - 59)
# | ——Hour(0 - 23)
# | | ——Day(1 - 31)
# | | | ——Month(1 - 12)
# | | | | ——Week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * *
Set the key parameters of each job in the CronJob as required:
Note:
If you select Kingsoft Cloud Elastic Block Storage, the volume name is the ID of the EBS instance and cannot be modified.
Create containers:
Name: the name of the container, which can be up to 63 characters in length, and can contain lowercase letters, digits, and hyphens (-). The name must start with a lowercase letter and end with a lowercase letter or a digit.
Image: the image of the container. You can enter the address of an image repository, or click Select Image to select an image from an image repository.
Tag: the tag of the image.
Resources: the limits on the CPU and memory resources for the container.
VolumeMount: the mount path and read/write privilege of the volume. This item is available only when a volume is added.
This item is available when you pull images from a private image repository. This item corresponds to imagePullSecret in the YAML file.
After the configuration is completed, click Create and check the CronJob status on the CronJob list page.
To run or stop a CronJob, click Run or Stop for the CronJob in the CronJob list.
Click a CronJob name in the CronJob list to enter the details page. In the job list, you can view the running status of created jobs of the CronJob. To view details about a job, click the job name.
To delete a CronJob, go to the CronJob list page, move your pointer over More, and then click Delete for the CronJob. In the message that appears, click OK. To delete a specific job of a CronJob, go to the job list of the CronJob and click Delete for the job.
To create a CronJob by using a YAML file, click Create Resources by YAML on the CronJob list page. To update an existing CronJob by using a YAML file, click Edit YAML in the CronJob list.
The following sample YAML file describes how to create a CronJob to send greetings every minute. hello-cronjob.yaml:
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: OnFailure
Create the CronJob
$ kubectl apply -f hello-cronjob.yaml
The following section describes how to create a CronJob without complete configuration information by running the kubectl run command.
$ kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello"
Check the CronJob status
$ kubectl get cronjob
Pure Mode