Followers

kubernetes-Jobs

 A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created.

A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot).

You can also use a Job to run multiple Pods in parallel.

LAB

1. Job manifest file: 



apiVersion: batch/v1
kind: Job
metadata:
  name: countdown
spec:
  template:
    metadata:
      name: countdown
    spec:
      containers:
      - name: counter
        image: centos:7
        command:
         - "bin/bash"
         - "-c"
         - "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done"
      restartPolicy: Never

2. Create & Display


kubectl create -f countdown-jobs.yaml

kubectl get jobs

kubectl get po

kubectl describe jobs countdown



*************************************************************************************************************************************************

3. Test


kubectl logs [POD_NAME] 



*************************************************************************************************************************************************

4. Cleanup


kubectl delete jobs countdown

kubectl get po



**************Cron Job***********************

#cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
   name: cronjob
spec:
   schedule: "* * * * *"
   successfulJobsHistoryLimit: 2
   failedJobsHistoryLimit: 1
   jobTemplate:
     spec:
       template:
         spec:
           containers:
           - name: busybox
             image: busybox
             command: ["echo", "Hello world"]
           restartPolicy: Never

kubectl create -f cronjob.yaml


kubectl patch cronjob cronjob -p '{"spec":{"suspend":true}}'


concurrencyPolicy:   Allow,Forbid,Replace

Allow to allow multiple jobs runs at a time

Forbid to wait a running job to finish first and then execute another instance of the job

Replace to replace an existing job.

Namespaces

COMMENTS

BLOGGER: 2
  1. How I can run the python and Java script both code through single yml file in kubernate..

    ReplyDelete
    Replies
    1. w.r.t Cronjobs

      If the schedule is same then you can create multi containers and run it in same job file.
      You can define multiple schedule in single file by seprating it with ---
      eg
      cronjob1 code (first job code)
      -----
      cronjob2 code (second job code)

      Delete

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
static_page
DevOpsWorld: kubernetes-Jobs
kubernetes-Jobs
DevOpsWorld
https://www.devopsworld.co.in/p/kubernetes-jobs.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/p/kubernetes-jobs.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content