17. Kubernetes Jobs and CronJobs

Опубликовано: 26 Ноябрь 2024
на канале: iMustLearn
271
3

** Example:1 **
vi my-busybox-cj.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
echo Hello from the Kubernetes cluster
restartPolicy: OnFailure

kubectl create -f my-busybox-cj.yaml

kubectl get cronjobs

kubectl get cronjobs

kubectl get pods

kubectl logs [hello-xxxx-xxxxx]

*** Example:2 ***
vi my-perl-job.yaml

apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4

kubectl create -f my-perl-job.yaml

kubectl get jobs

kubectl get pods

kubectl logs [pi-xxxx-xxxx]