tencent cloud

Tencent Kubernetes Engine

Release Notes and Announcements
Release Notes
Announcements
Release Notes
Product Introduction
Overview
Strengths
Architecture
Scenarios
Features
Concepts
Native Kubernetes Terms
Common High-Risk Operations
Regions and Availability Zones
Service Regions and Service Providers
Open Source Components
Purchase Guide
Purchase Instructions
Purchase a TKE General Cluster
Purchasing Native Nodes
Purchasing a Super Node
Getting Started
Beginner’s Guide
Quickly Creating a Standard Cluster
Examples
Container Application Deployment Check List
Cluster Configuration
General Cluster Overview
Cluster Management
Network Management
Storage Management
Node Management
GPU Resource Management
Remote Terminals
Application Configuration
Workload Management
Service and Configuration Management
Component and Application Management
Auto Scaling
Container Login Methods
Observability Configuration
Ops Observability
Cost Insights and Optimization
Scheduler Configuration
Scheduling Component Overview
Resource Utilization Optimization Scheduling
Business Priority Assurance Scheduling
QoS Awareness Scheduling
Security and Stability
TKE Security Group Settings
Identity Authentication and Authorization
Application Security
Multi-cluster Management
Planned Upgrade
Backup Center
Cloud Native Service Guide
Cloud Service for etcd
TMP
TKE Serverless Cluster Guide
TKE Registered Cluster Guide
Use Cases
Cluster
Serverless Cluster
Scheduling
Security
Service Deployment
Network
Release
Logs
Monitoring
OPS
Terraform
DevOps
Auto Scaling
Containerization
Microservice
Cost Management
Hybrid Cloud
AI
Troubleshooting
Disk Full
High Workload
Memory Fragmentation
Cluster DNS Troubleshooting
Cluster kube-proxy Troubleshooting
Cluster API Server Inaccessibility Troubleshooting
Service and Ingress Inaccessibility Troubleshooting
Common Service & Ingress Errors and Solutions
Engel Ingres appears in Connechtin Reverside
CLB Ingress Creation Error
Troubleshooting for Pod Network Inaccessibility
Pod Status Exception and Handling
Authorizing Tencent Cloud OPS Team for Troubleshooting
CLB Loopback
API Documentation
History
Introduction
API Category
Making API Requests
Elastic Cluster APIs
Resource Reserved Coupon APIs
Cluster APIs
Third-party Node APIs
Relevant APIs for Addon
Network APIs
Node APIs
Node Pool APIs
TKE Edge Cluster APIs
Cloud Native Monitoring APIs
Scaling group APIs
Super Node APIs
Other APIs
Data Types
Error Codes
TKE API 2022-05-01
FAQs
TKE General Cluster
TKE Serverless Cluster
About OPS
Hidden Danger Handling
About Services
Image Repositories
About Remote Terminals
Event FAQs
Resource Management
Service Agreement
TKE Service Level Agreement
TKE Serverless Service Level Agreement
Contact Us
Glossary

CronJob Management

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2024-12-19 22:09:58

Overview

A CronJob object is similar to a line in a crontab (cron table) file. It periodically runs a Job according to the specified schedule.

Operation Guide for CronJobs in the Console

Creating a CronJob

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to go to the cluster management page.
3. Click the ID of the cluster where CronJob needs to be created to enter the cluster management page.
4. Select Workload > CronJob to go to the CronJob information page. See the figure below:


5. Click Create to open the Create Workload page.
6. Set the CronJob parameters based on your actual needs. The key parameters are as follows:
Workload Name: custom.
Label: a key-value pair, which is used for classified management of resources.
Namespace: select a namespace based on your requirements.
Type: select CronJob (running according to a cron schedule).
Scheduling Rules: select a periodic execution policy based on your business requirements.
Completed Jobs Retained: it corresponds to .spec.successfulJobsHistoryLimit. For more information, see Jobs History Limits.
Failed Jobs Retained: it corresponds to .spec.failedJobsHistoryLimit. For more information, see Jobs History Limits.
Job Settings:
Repeat Times: set the number of times the Pod in the Job needs to be repeated.
Concurrent Pods: set the number of Pods that the Job runs in parallel.
Restart Policy: set the restart policy applied when containers under the Pod exits exceptionally.
Never: do not restart the container until all containers in the Pod exit.
OnFailure: the Pod continues to run and the container will be restarted.
Volume (optional): provides storage for the container. It can be a temp path, CVM path, CBS volume, file storage NFS, configuration file and PVC, and it must be mounted to the specified path of the container.
Containers in the Pod: set one or more different containers for a Pod of the CronJob based on actual needs.
Name: custom.
Image: select as needed.
Image Tag: enter the tag based on your actual needs.
Image Pull Policy: the following three policies are available. Select as needed. If you do not set any image pull policy and Image Tag is left empty or set to latest, the Always policy is used. Otherwise, the IfNotPresent policy is used.
Always: always pull the image from the remote end.
IfNotPresent: a local image is used by default. If no local image is available, the image is pulled remotely.
Never: only use a local image. If no local image is available, an exception occurs.
CPU/Memory Limit: set the CPU and memory limit according to Kubernetes' resource limits to improve the robustness of the business.
GPU Resource: you can configure the least GPU resource used by the workload.
Advanced Settings: you can set the parameters such as Working Directory, Running Command, Running Parameter, Container Health Check, and Privileged Container.
Image Access Credential: a container image is private by default. You need to select the image access credential for the TCR instance when creating a workload.
Node Scheduling Policy: the Pod can be scheduled to the node of the Label that meets the expectation according to the scheduling rules.
7. Click Create Workload to complete the process.

Viewing CronJob status

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to go to the cluster management page.
3. Click the ID of the cluster where CronJob status needs to be checked to enter the cluster management page.
4. Select Workload > CronJob to go to the CronJob information page.
5. Click the name of the CronJob for which to view the status to view its details.

Using kubectl to Manipulate CronJobs

YAML sample

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
kind: this identifies the CronJob resource type.
metadata: basic information such as CronJob name and Label.
metadata.annotations: an additional description of the CronJob. You can set additional enhancements to TKE through this parameter.
spec.schedule: the cron policy run by the CronJob.
spec.jobTemplate: the Job template run by Cron.

Creating a CronJob

Method 1

1. See the YAML sample to prepare the CronJob YAML file.
2. Install kubectl and connect to a cluster. For detailed operations, see Connecting to a Cluster.
3. Run the following command to create the CronJob YAML file.
kubectl create -f CronJob YAML filename
For example, to create a CronJob YAML file named cronjob.yaml, run the following command:
kubectl create -f cronjob.yaml

Method 2

1. Quickly create a CronJob by running the kubectl run command. For example, to quickly create a CronJob that does not need to write full configuration information, run the following command:
kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello"
2. Run the following command to see if the item is successfully created.
kubectl get cronjob [NAME]
If a message similar to the following is returned, the creation is successful.
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
cronjob * * * * * False 0 <none> 15s

Deleting a CronJob

Note:
Before running this deletion command, please confirm whether there is a Job being created; if yes, running this command will terminate that Job.
When you run this deletion command, created Jobs and completed Jobs will not be terminated or deleted.
To delete a Job created by CronJob, please do so manually.
Run the following command to delete a CronJob.
kubectl delete cronjob [NAME]


Ajuda e Suporte

Esta página foi útil?

comentários