Giriş
Açıklaması şöyle
spec > schedule: specify the cron expression for how frequently the container has to be invokedcontainers > image: image name which was built in previous stepssuccessFulJobsHistoryLimit: keep the metadata related to the last ’n’ successful jobs for debugging or log monitoring
Örnek - veri tabanı yedekleme
Şöyle yaparız.
schedule her gece çalışacağını belirtir
restartPolicy gerekirse tekrar başlayacağını belirtir
apiVersion: batch/v1 kind: CronJob metadata: name: db-backup spec: schedule: "0 0 * * *" jobTemplate: spec: template: spec: restartPolicy: OnFailure volumes: - name: backup-volume hostPath: path: /mnt/backup containers: - name: db-backup image: mysql:5.7 args: - mysqldump - --host=<database host> - --user=root - --password=<database password> - --result-file=/mnt/backup/all-databases.sql - <database name> volumeMounts: - name: backup-volume mountPath: /mnt/backup
Örnek
Şöyle yaparız
apiVersion: batch/v1kind: CronJobmetadata:name: reporting-jobspec:schedule: "0 8 * * *"successfulJobsHistoryLimit: 1failedJobsHistoryLimit: 5jobTemplate:spec:template:spec:containers:- name: reportingimage: reportingservice:1.0.0imagePullPolicy: IfNotPresentrestartPolicy: OnFailure
Şöyle yaparız
# get the cron job state kubectl get cronjob # for continuous monitoring kubectl get jobs --watch # to View logs # Replace "reporting-job-706356" with the job name in your system pods=$(kubectl get pods \ --selector=job-name=reporting-job-706356 \ --output=jsonpath={.items[*].metadata.name}) kubectl logs $pods
Hiç yorum yok:
Yorum Gönder